protomotions.agents.base_agent.model module#
Base model interface for agent neural networks.
This module defines the abstract base class that all agent models must implement. It provides a TensorDictModule interface for clean, compilable models.
- Key Classes:
BaseModel: Abstract base class for all agent models (TensorDictModule)
- class protomotions.agents.base_agent.model.RolloutStateSpec(shape=(), init='zeros', dtype=<Mock object>)[source]#
Bases:
objectDeclared model-owned per-env rollout context.
A model declares the tensor shape, dtype, and initial-value distribution for per-env context that must be carried during rollout and replayed during optimization. The framework owns when context is initialized and which rows are reset after episode boundaries.
- __init__(shape=(), init='zeros', dtype=<Mock object>)#
- class protomotions.agents.base_agent.model.ProtoMotionsTensorDictModule(*args, **kwargs)[source]#
Bases:
TensorDictModuleBaseCommon contract for ProtoMotions-owned TensorDict modules.
Use this for modules that read and write named TensorDict keys and may own rollout state that must be saved in the experience buffer. Examples include policy/critic modules, normalizing observation processors, container modules, and models with rollout-local latent state.
- forward(tensordict, log_internals=False)[source]#
Forward pass for ProtoMotions TensorDict modules.
log_internalsis part of the common contract. Modules that produce diagnostics can honor it; stateless modules can ignore it.
- reset_rollout_context(
- env_ids=None,
- num_envs=None,
- device=None,
Initialize or reseed model-owned context carried across rollout steps.
num_envsanddeviceare supplied once during setup, after the simulator is built. Later calls pass onlyenv_idsto reseed rows for environments that just ended. This method intentionally does not infer shape/device changes mid-run; rebuilding the simulator should call setup again and reinitialize explicitly.
- init_rollout_state(num_envs, device)[source]#
Allocate declared rollout-context buffers for this module tree.
- reset_rollout_state(env_ids=None)[source]#
Reseed selected rows for this module tree’s rollout context.
- read_rollout_state(tensordict)[source]#
Inject carried rollout context into
tensordictwhen absent.Rollout forwards read from model-owned buffers; optimization forwards read replayed values already present in the batch. This helper makes the distinction explicit and avoids each model hand-writing buffer fallbacks.
- class protomotions.agents.base_agent.model.BaseModel(*args, **kwargs)[source]#
Bases:
ProtoMotionsTensorDictModuleBase class for all agent models.
All models are TensorDictModules with a single forward method that processes observations and returns all model outputs in a TensorDict.
- Parameters:
config (BaseModelConfig) – Model configuration with architecture parameters.
- config#
Stored configuration for the model.
- in_keys#
Input keys for TensorDict (set by subclasses).
- out_keys#
Output keys for TensorDict (default: [“action”]).