embodichain.learning#
Learning systems.
Currently exposes the rl subpackage for on-policy reinforcement learning.
Submodules
On-policy reinforcement learning pipeline. |
Reinforcement Learning#
On-policy reinforcement learning pipeline.
Algorithms (PPO/GRPO), rollout buffers, collectors, policy/model builders, and the training entry point; rollout data flows as TensorDict objects.
Algorithm registry and construction helpers ( |
|
On-policy rollout buffer ( |
|
Collectors that step vectorized environments and assemble rollout data into a preallocated |
|
Policy-network registration and model construction ( |
|
RL helper utilities: algorithm config, optimizers, and observation helpers. |
Classes:
Coordinate APG updates and truncated-backpropagation boundaries. |
|
Configuration for graph-preserving segmented training. |
|
Batched env that preserves the autograd path through |
|
Structural interface shared by lightweight vector environments. |
Functions:
|
Build a registered lightweight vector environment. |
|
Evaluate exactly |
Return registered lightweight environment names. |
|
|
Return the trainer compatible with |
|
Register a lightweight vector-environment factory. |
- class embodichain.learning.rl.DifferentiableTrainer[source]#
Bases:
objectCoordinate APG updates and truncated-backpropagation boundaries.
Methods:
__init__(cfg, env, policy, algorithm[, ...])Return the current in-memory training summary.
load_checkpoint(path)Restore policy, optimizer, and trainer counters.
save_checkpoint([path])Save policy, optimizer, and trainer counters.
train(total_timesteps)Train until at least
total_timestepsvector transitions exist.
- class embodichain.learning.rl.DifferentiableTrainerCfg[source]#
Bases:
objectConfiguration for graph-preserving segmented training.
Methods:
__init__([segment_length, update_horizon, ...])copy(**kwargs)Return a new object replacing specified fields with new values.
replace(**kwargs)Return a new object replacing specified fields with new values.
to_dict()Convert an object into dictionary recursively.
validate([prefix])Check the validity of configclass object.
Attributes:
- __init__(segment_length=<factory>, update_horizon=<factory>, deterministic_actions=<factory>, checkpoint_dir=<factory>, experiment_name=<factory>, save_frequency_updates=<factory>, eval_frequency_steps=<factory>, num_eval_episodes=<factory>, eval_seed=<factory>, use_wandb=<factory>, best_eval_metric=<factory>, best_eval_mode=<factory>)#
-
best_eval_metric:
str#
-
best_eval_mode:
str#
-
checkpoint_dir:
str#
- copy(**kwargs)#
Return a new object replacing specified fields with new values.
This is especially useful for frozen classes. Example usage:
@configclass(frozen=True) class C: x: int y: int c = C(1, 2) c1 = c.replace(x=3) assert c1.x == 3 and c1.y == 2
- Parameters:
obj (
object) – The object to replace.**kwargs – The fields to replace and their new values.
- Return type:
object- Returns:
The new object.
-
deterministic_actions:
bool#
-
eval_frequency_steps:
int#
-
eval_seed:
int|None#
-
experiment_name:
str#
-
num_eval_episodes:
int#
- replace(**kwargs)#
Return a new object replacing specified fields with new values.
This is especially useful for frozen classes. Example usage:
@configclass(frozen=True) class C: x: int y: int c = C(1, 2) c1 = c.replace(x=3) assert c1.x == 3 and c1.y == 2
- Parameters:
obj (
object) – The object to replace.**kwargs – The fields to replace and their new values.
- Return type:
object- Returns:
The new object.
-
save_frequency_updates:
int#
-
segment_length:
int#
- to_dict()#
Convert an object into dictionary recursively.
Note
Ignores all names starting with “__” (i.e. built-in methods).
- Parameters:
obj (
object) – An instance of a class to convert.- Raises:
ValueError – When input argument is not an object.
- Return type:
dict[str,Any]- Returns:
Converted dictionary mapping.
-
update_horizon:
int|None#
-
use_wandb:
bool#
- validate(prefix='')#
Check the validity of configclass object.
This function checks if the object is a valid configclass object. A valid configclass object contains no MISSING entries.
- Parameters:
obj (
object) – The object to check.prefix (
str) – The prefix to add to the missing fields. Defaults to ‘’.
- Return type:
list[str]- Returns:
A list of missing fields.
- Raises:
TypeError – When the object is not a valid configuration object.
- class embodichain.learning.rl.DifferentiableVecEnv[source]#
Bases:
LearningVecEnv,ProtocolBatched env that preserves the autograd path through
step.detach_stateis the truncated-backpropagation boundary: detach differentiable internal state and return the current observation without resetting or resampling the episode. Finished rows must auto-reset insidestep, returning the terminal reward/done with the next initial observation.Methods:
Detach internal state and return its current detached observation.
- class embodichain.learning.rl.LearningVecEnv[source]#
Bases:
ProtocolStructural interface shared by lightweight vector environments.
Methods:
__init__(*args, **kwargs)close()Release owned resources.
reset(*[, seed, options])Reset all environments and return the initial observation.
step(action)Advance all environments by one step.
Attributes:
- __init__(*args, **kwargs)#
-
device:
device#
-
num_envs:
int#
- reset(*, seed=None, options=None)[source]#
Reset all environments and return the initial observation.
- Return type:
tuple[Tensor|TensorDict,dict[str,Any]]
-
single_action_space:
Space#
-
single_observation_space:
Space#
- embodichain.learning.rl.build_learning_env(name, *, num_envs, device, **cfg)[source]#
Build a registered lightweight vector environment.
- Return type:
- embodichain.learning.rl.evaluate_episodes(*, policy, env, num_episodes, device, seed=None, on_step=None)[source]#
Evaluate exactly
num_episodescompleted asynchronous episodes.- Return type:
dict[str,float]
- embodichain.learning.rl.get_registered_learning_env_names()[source]#
Return registered lightweight environment names.
- Return type:
list[str]
- embodichain.learning.rl.get_trainer_class(algorithm)[source]#
Return the trainer compatible with
algorithm.- Return type:
type[Trainer] |type[DifferentiableTrainer]
- embodichain.learning.rl.register_learning_env(name, factory=None, *, override=False)[source]#
Register a lightweight vector-environment factory.
The function supports both
@register_learning_env("Name")and directregister_learning_env("Name", Factory)use.- Return type:
Callable[[Callable[...,LearningVecEnv]],Callable[...,LearningVecEnv]] |Callable[...,LearningVecEnv]