| ActorVectorField |
Ran ran on a synthesized input · constructed an object; no result was computed |
aoberai/trl/agents/trl.py code served (permissive licence) · get_code("df83a46f0c516728") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, ActorVectorField: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import jax
import jax.numpy as jnp
import flax.linen as nn
from typing import Sequence, Any
# Create a minimal GCEncoder that encodes observations and goals
class MinimalGCEncoder(nn.Module):
"""Minimal encoder for goal-conditioned observations."""
output_dim: int = 8
@nn.compact
def __call__(self, observations, goals=None):
# Simple encoding: concatenate and apply a dense layer
if goals is not None:
x = jnp.concatenate([observations, goals], axis=-1)
else:
x = observations
x = nn.Dense(self.output_dim)(x)
return x
def default_init(scale=1.0):
"""Default kernel initializer."""
return nn.initializers.variance_scaling(scale, 'fan_avg', 'uniform')
class MLP(nn.Module):
"""Multi-layer perceptron (MLP)."""
hidden_dims: Sequence[int]
activations: Any = nn.gelu
activate_final: bool = False
kernel_init: Any = default_init()
layer_norm: bool = False
@nn.compact
def __call__(self, x):
for i, size in enumerate(self.hidden_dims):
x = nn.Dense(size, kernel_init=self.kernel_init)(x)
if i + 1 < len(self.hidden_dims) or self.activate_final:
x = self.activations(x)
if self.layer_norm:
x = nn.LayerNorm()(x)
if i == len(self.hidden_dims) - 2:
self.sow('intermediates', 'feature', x)
return x
class ActorVectorField(nn.Module):
"""Actor vector field for flow policies."""
hidden_dims: Sequence[int]
action_dim: int
mlp_class: Any = MLP
activate_final: bool = False
layer_norm: bool = False
gc_encoder: nn.Module = None
def setup(self) -> None:
self.mlp = self.mlp_class((*self.hidden_dims, self.action_dim), activate_final=False, layer_norm=self.layer_norm)
@nn.compact
def __call__(self, observations, goals=None, actions=None, times=None, is_encoded=False):
"""Return the current vector."""
if not is_encoded and self.gc_encoder is not None:
if goals is None:
inputs = self.gc_encoder(observations)
else:
inputs = self.gc_encoder(observations, goals)
elif goals is None:
inputs = observations
else:
inputs = jnp.concatenate([observations, goals], axis=-1)
if times is None:
inputs = jnp.concatenate([inputs, actions], axis=-1)
else:
inputs = jnp.concatenate([inputs, actions, times], axis=-1)
v = self.mlp(inputs)
return v
# Construct ARGS dictionary
ARGS = {
'hidden_dims': (16, 32),
'action_dim': 3,
'mlp_class': MLP,
'activate_final': False,
'layer_norm': False,
'gc_encoder': MinimalGCEncoder(output_dim=8),
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- flax, jax — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type ActorVectorField — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a ActorVectorField output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| GCDiscreteActor |
Ran ran on a synthesized input · constructed an object; no result was computed |
aoberai/trl/agents/trl.py code served (permissive licence) · get_code("f819282a86b116af") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, GCDiscreteActor: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import jax
import jax.numpy as jnp
import flax.linen as nn
import distrax
def default_init(scale=1.0):
"""Default kernel initializer."""
return nn.initializers.variance_scaling(scale, 'fan_avg', 'uniform')
class MLP(nn.Module):
"""Multi-layer perceptron (MLP)."""
hidden_dims: tuple
activations: any = nn.gelu
activate_final: bool = False
kernel_init: any = default_init()
layer_norm: bool = False
@nn.compact
def __call__(self, x):
for i, size in enumerate(self.hidden_dims):
x = nn.Dense(size, kernel_init=self.kernel_init)(x)
if i + 1 < len(self.hidden_dims) or self.activate_final:
x = self.activations(x)
if self.layer_norm:
x = nn.LayerNorm()(x)
if i == len(self.hidden_dims) - 2:
self.sow('intermediates', 'feature', x)
return x
class GCDiscreteActor(nn.Module):
"""Goal-conditioned actor for discrete actions."""
hidden_dims: tuple
action_dim: int
mlp_class: any = MLP
layer_norm: bool = False
final_fc_init_scale: float = 0.01
gc_encoder: nn.Module = None
def setup(self):
self.actor_net = self.mlp_class(self.hidden_dims, activate_final=True, layer_norm=self.layer_norm)
self.logit_net = nn.Dense(self.action_dim, kernel_init=default_init(self.final_fc_init_scale))
def __call__(self, observations, goals=None, goal_encoded=False, temperature=1.0):
if self.gc_encoder is not None:
inputs = self.gc_encoder(observations, goals, goal_encoded=goal_encoded)
else:
inputs = [observations]
if goals is not None:
inputs.append(goals)
inputs = jnp.concatenate(inputs, axis=-1)
outputs = self.actor_net(inputs)
logits = self.logit_net(outputs)
distribution = distrax.Categorical(logits=logits / jnp.maximum(1e-06, temperature))
return distribution
# Create a simple GCEncoder stand-in if needed
class SimpleGCEncoder(nn.Module):
"""Simple encoder that concatenates observations and goals."""
@nn.compact
def __call__(self, observations, goals=None, goal_encoded=False):
if goals is not None:
return jnp.concatenate([observations, goals], axis=-1)
return observations
# Build setup arguments for GCDiscreteActor
ARGS = {
'hidden_dims': (8, 6),
'action_dim': 5,
'mlp_class': MLP,
'layer_norm': False,
'final_fc_init_scale': 0.01,
'gc_encoder': None,
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- distrax, flax, jax — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type GCDiscreteActor — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a GCDiscreteActor output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| GCDiscreteCritic |
Ran ran on a synthesized input · constructed an object; no result was computed |
aoberai/trl/agents/trl.py code served (permissive licence) · get_code("ec0fa56861db80dc") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, GCDiscreteCritic: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import jax
import jax.numpy as jnp
import flax.linen as nn
from typing import Sequence, Any
def default_init(scale=1.0):
"""Default kernel initializer."""
return nn.initializers.variance_scaling(scale, 'fan_avg', 'uniform')
def ensemblize(cls, num_qs, in_axes=None, out_axes=0, **kwargs):
"""Ensemblize a module."""
return nn.vmap(cls, variable_axes={'params': 0, 'intermediates': 0}, split_rngs={'params': True}, in_axes=in_axes, out_axes=out_axes, axis_size=num_qs, **kwargs)
class MLP(nn.Module):
"""Multi-layer perceptron (MLP)."""
hidden_dims: Sequence[int]
activations: Any = nn.gelu
activate_final: bool = False
kernel_init: Any = default_init()
layer_norm: bool = False
@nn.compact
def __call__(self, x):
for i, size in enumerate(self.hidden_dims):
x = nn.Dense(size, kernel_init=self.kernel_init)(x)
if i + 1 < len(self.hidden_dims) or self.activate_final:
x = self.activations(x)
if self.layer_norm:
x = nn.LayerNorm()(x)
if i == len(self.hidden_dims) - 2:
self.sow('intermediates', 'feature', x)
return x
class GCValue(nn.Module):
"""Goal-conditioned value/critic function."""
hidden_dims: Sequence[int]
output_dim: int = None
mlp_class: Any = MLP
layer_norm: bool = True
num_ensembles: int = 2
gc_encoder: nn.Module = None
def setup(self):
mlp_class = self.mlp_class
if self.num_ensembles > 1:
mlp_class = ensemblize(mlp_class, self.num_ensembles)
output_dim = self.output_dim if self.output_dim is not None else 1
value_net = mlp_class((*self.hidden_dims, output_dim), activate_final=False, layer_norm=self.layer_norm)
self.value_net = value_net
def __call__(self, observations, goals=None, actions=None):
"""Return the value/critic function."""
if self.gc_encoder is not None:
if goals is None:
inputs = [self.gc_encoder(observations)]
else:
inputs = [self.gc_encoder(observations, goals)]
else:
inputs = [observations]
if goals is not None:
inputs.append(goals)
if actions is not None:
inputs.append(actions)
inputs = jnp.concatenate(inputs, axis=-1)
v = self.value_net(inputs)
if self.output_dim is None:
v = v.squeeze(-1)
return v
class GCDiscreteCritic(GCValue):
"""Goal-conditioned critic for discrete actions."""
action_dim: int = None
def __call__(self, observations, goals=None, actions=None):
actions = jnp.eye(self.action_dim)[actions]
return super().__call__(observations, goals, actions)
# Create test arguments
ARGS = {
'hidden_dims': (8, 6),
'output_dim': 1,
'mlp_class': MLP,
'layer_norm': True,
'num_ensembles': 2,
'gc_encoder': None,
'action_dim': 3,
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- flax, jax — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type GCDiscreteCritic — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a GCDiscreteCritic output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| GCValue |
Ran ran on a synthesized input · constructed an object; no result was computed |
aoberai/trl/agents/trl.py code served (permissive licence) · get_code("d37de0a9bc304852") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, GCValue: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import jax
import jax.numpy as jnp
import flax.linen as nn
from typing import Sequence, Any
def default_init(scale=1.0):
"""Default kernel initializer."""
return nn.initializers.variance_scaling(scale, 'fan_avg', 'uniform')
def ensemblize(cls, num_qs, in_axes=None, out_axes=0, **kwargs):
"""Ensemblize a module."""
return nn.vmap(cls, variable_axes={'params': 0, 'intermediates': 0}, split_rngs={'params': True}, in_axes=in_axes, out_axes=out_axes, axis_size=num_qs, **kwargs)
class MLP(nn.Module):
"""Multi-layer perceptron (MLP)."""
hidden_dims: Sequence[int]
activations: Any = nn.gelu
activate_final: bool = False
kernel_init: Any = default_init()
layer_norm: bool = False
@nn.compact
def __call__(self, x):
for i, size in enumerate(self.hidden_dims):
x = nn.Dense(size, kernel_init=self.kernel_init)(x)
if i + 1 < len(self.hidden_dims) or self.activate_final:
x = self.activations(x)
if self.layer_norm:
x = nn.LayerNorm()(x)
if i == len(self.hidden_dims) - 2:
self.sow('intermediates', 'feature', x)
return x
class GCValue(nn.Module):
"""Goal-conditioned value/critic function."""
hidden_dims: Sequence[int]
output_dim: int = None
mlp_class: Any = MLP
layer_norm: bool = True
num_ensembles: int = 2
gc_encoder: nn.Module = None
def setup(self):
mlp_class = self.mlp_class
if self.num_ensembles > 1:
mlp_class = ensemblize(mlp_class, self.num_ensembles)
output_dim = self.output_dim if self.output_dim is not None else 1
value_net = mlp_class((*self.hidden_dims, output_dim), activate_final=False, layer_norm=self.layer_norm)
self.value_net = value_net
def __call__(self, observations, goals=None, actions=None):
"""Return the value/critic function."""
if self.gc_encoder is not None:
if goals is None:
inputs = [self.gc_encoder(observations)]
else:
inputs = [self.gc_encoder(observations, goals)]
else:
inputs = [observations]
if goals is not None:
inputs.append(goals)
if actions is not None:
inputs.append(actions)
inputs = jnp.concatenate(inputs, axis=-1)
v = self.value_net(inputs)
if self.output_dim is None:
v = v.squeeze(-1)
return v
# Simple GCEncoder stand-in that processes observations and goals
class SimpleGCEncoder(nn.Module):
"""Simple goal-conditioned encoder."""
@nn.compact
def __call__(self, observations, goals=None):
if goals is None:
return observations
else:
return jnp.concatenate([observations, goals], axis=-1)
ARGS = {
'hidden_dims': (8, 6),
'output_dim': 1,
'mlp_class': MLP,
'layer_norm': True,
'num_ensembles': 2,
'gc_encoder': SimpleGCEncoder(),
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- flax, jax — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type GCValue — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a GCValue output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| MLP |
Ran ran on a synthesized input · constructed an object; no result was computed |
aoberai/trl/agents/trl.py code served (permissive licence) · get_code("29c2c254a8d12929") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, MLP: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import jax
import jax.numpy as jnp
import flax.linen as nn
from typing import Sequence, Any
def default_init(scale=1.0):
"""Default kernel initializer."""
return nn.initializers.variance_scaling(scale, 'fan_avg', 'uniform')
ARGS = {
'hidden_dims': (8, 6, 4),
'activations': nn.gelu,
'activate_final': False,
'kernel_init': default_init(),
'layer_norm': False,
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- flax, jax — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type MLP — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a MLP output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| ModuleDict |
Ran ran on a synthesized input · constructed an object; no result was computed |
aoberai/trl/agents/trl.py code served (permissive licence) · get_code("c01fb7c1e74ffce4") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, ModuleDict: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import flax.linen as nn
import jax
import jax.numpy as jnp
from typing import Dict, Mapping, Sequence
# Define small test modules
class SimpleLinear(nn.Module):
features: int
@nn.compact
def __call__(self, x):
return nn.Dense(self.features)(x)
class SimpleConv(nn.Module):
features: int
@nn.compact
def __call__(self, x):
return nn.Conv(self.features, kernel_size=(3,))(x)
class IdentityModule(nn.Module):
@nn.compact
def __call__(self, x):
return x
# Create module dictionary with distinct modules
modules_dict = {
'linear': SimpleLinear(features=3),
'conv': SimpleConv(features=5),
'identity': IdentityModule()
}
# Construct ARGS
ARGS = {
'modules': modules_dict
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- flax, jax — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type ModuleDict — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a ModuleDict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| TrainState |
Ran ran on a synthesized input · constructed an object; no result was computed |
aoberai/trl/agents/trl.py code served (permissive licence) · get_code("320b57aeb460d8c6") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, TrainState: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import jax
import jax.numpy as jnp
import flax
import flax.linen as nn
import optax
import functools
nonpytree_field = functools.partial(flax.struct.field, pytree_node=False)
class SimpleModel(nn.Module):
"""Minimal Flax model for testing."""
features: int = 4
@nn.compact
def __call__(self, x):
x = nn.Dense(self.features)(x)
return x
# Initialize model and get params
model = SimpleModel(features=4)
key = jax.random.PRNGKey(0)
dummy_input = jnp.ones((2, 3))
params = model.init(key, dummy_input)['params']
# Create optimizer
tx = optax.adam(learning_rate=0.001)
# Create TrainState instance
train_state = None
class TrainState(flax.struct.PyTreeNode):
"""Custom train state for models."""
step: int
apply_fn: any = nonpytree_field()
model_def: any = nonpytree_field()
params: any
tx: any = nonpytree_field()
opt_state: any
@classmethod
def create(cls, model_def, params, tx=None, **kwargs):
"""Create a new train state."""
if tx is not None:
opt_state = tx.init(params)
else:
opt_state = None
return cls(step=1, apply_fn=model_def.apply, model_def=model_def, params=params, tx=tx, opt_state=opt_state, **kwargs)
def __call__(self, *args, params=None, method=None, **kwargs):
"""Forward pass."""
if params is None:
params = self.params
variables = {'params': params}
if method is not None:
method_name = getattr(self.model_def, method)
else:
method_name = None
return self.apply_fn(variables, *args, method=method_name, **kwargs)
def select(self, name):
"""Helper function to select a module from a `ModuleDict`."""
return functools.partial(self, name=name)
def apply_gradients(self, grads, **kwargs):
"""Apply the gradients and return the updated state."""
updates, new_opt_state = self.tx.update(grads, self.opt_state, self.params)
new_params = optax.apply_updates(self.params, updates)
return self.replace(step=self.step + 1, params=new_params, opt_state=new_opt_state, **kwargs)
def apply_loss_fn(self, loss_fn):
"""Apply the loss function and return the updated state and info."""
grads, info = jax.grad(loss_fn, has_aux=True)(self.params)
grad_max = jax.tree_util.tree_map(jnp.max, grads)
grad_min = jax.tree_util.tree_map(jnp.min, grads)
grad_norm = jax.tree_util.tree_map(jnp.linalg.norm, grads)
grad_max_flat = jnp.concatenate([jnp.reshape(x, -1) for x in jax.tree_util.tree_leaves(grad_max)], axis=0)
grad_min_flat = jnp.concatenate([jnp.reshape(x, -1) for x in jax.tree_util.tree_leaves(grad_min)], axis=0)
grad_norm_flat = jnp.concatenate([jnp.reshape(x, -1) for x in jax.tree_util.tree_leaves(grad_norm)], axis=0)
final_grad_max = jnp.max(grad_max_flat)
final_grad_min = jnp.min(grad_min_flat)
final_grad_norm = jnp.linalg.norm(grad_norm_flat, ord=1)
info.update({'grad/max': final_grad_max, 'grad/min': final_grad_min, 'grad/norm': final_grad_norm})
return (self.apply_gradients(grads=grads), info)
# Create train state
train_state = TrainState.create(model_def=model, params=params, tx=tx)
ARGS = {
'step': 1,
'apply_fn': model.apply,
'model_def': model,
'params': params,
'tx': tx,
'opt_state': tx.init(params)
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- flax, jax, optax — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type TrainState — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a TrainState output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| GCActor |
Not yet run unverified (harvested, no recorded run) |
aoberai/trl/agents/trl.py code served (permissive licence) · get_code("0edea8d86dca9c85") How it ran |
| TRLAgent |
Not yet run unverified (harvested, no recorded run) |
aoberai/trl/agents/trl.py code served (permissive licence) · get_code("06f80dc2127d46de") How it ran |