opentau.configs.policies
Policy configuration module.
This module provides the base PreTrainedConfig class for policy models, which defines the interface and common functionality for all policy configurations. It includes support for feature definitions, normalization modes, and loading configurations from pretrained models or local paths.
Functions
|
Resolve |
|
Read a config JSON, resolve |
Remove deprecated and removed fields from a config JSON file in-place. |
|
|
Emit a deprecation warning if a config JSON file contains latency fields. |
Like |
|
|
Emit a deprecation warning if a config JSON file contains removed fields. |
|
Like |
Strip deprecated/removed fields from |
Classes
|
Base configuration class for policy models. |
- class opentau.configs.policies.PreTrainedConfig(n_obs_steps: int = 1, normalization_mapping: dict[str, ~opentau.configs.types.NormalizationMode] = <factory>, input_features: dict[str, ~opentau.configs.types.PolicyFeature] = <factory>, output_features: dict[str, ~opentau.configs.types.PolicyFeature] = <factory>, device: str | None = None, use_amp: bool = False, use_torch_compile: bool = False, torch_compile_mode: str = 'default', pretrained_path: str | None = None, skip_normalization_weights: bool = False, skip_input_resolution_check: bool = False, save_normalization_stats: bool = True, dataset_names: list[str] | None = None, dataset_to_norm_index: dict[str, int] | None = None, cloud_vlm_latency_mean: float = 0.0, cloud_vlm_latency_std: float = 0.0, cloud_vlm_latency_lower: float = 0.0, cloud_vlm_latency_upper: float = 0.0, action_decoder_latency_mean: float = 0.0, action_decoder_latency_std: float = 0.0, action_decoder_latency_lower: float = 0.0, action_decoder_latency_upper: float = 0.0)[source]
Bases:
ChoiceRegistry,HubMixin,ABCBase configuration class for policy models.
- Parameters:
n_obs_steps – Number of environment steps worth of observations to pass to the policy (takes the current step and additional steps going back).
input_shapes – A dictionary defining the shapes of the input data for the policy.
output_shapes – A dictionary defining the shapes of the output data for the policy.
input_normalization_modes – A dictionary with key representing the modality and the value specifies the normalization mode to apply.
output_normalization_modes – Similar dictionary as input_normalization_modes, but to unnormalize to the original scale.
skip_normalization_weights – When loading via
from_pretrained(), drop the savednormalize_*/unnormalize_*buffer tensors from the state dict beforeload_state_dict. The buffers freshly initialised fromdataset_statsthen survive — use this when finetuning a checkpoint whose saved normalization stats were aggregated over a different dataset mixture than the finetuning data. The buffers are registered asnn.Parameter(requires_grad=False), so training alone cannot recover from inheriting the wrong stats. Requires ``dataset_stats`` to be supplied to ``__init__`` (e.g. viaopentau.policies.factory.make_policy()); otherwise the buffers stay at theinfsentinel fromopentau.policies.normalize.create_stats_buffers()and the next forward crashes. One-shot (in-memory only): after the strip helper runs (whether keys were dropped or the “had no effect” warning fired), the flag is reset toFalseon the in-memory model’s config — a user who opted in once should not have to remember to flip it back before resume. Persistence requiressave_pretrained: an in-process resume that goestrain.py→save_checkpoint→cfg.save_pretrained(...)writesFalseto the new checkpoint’sconfig.json, so the nextfrom_pretrainedreadsFalseand skips the strip. But re-runningfrom_pretrainedon the original source checkpoint (e.g. an interactive notebook session that hasn’t yet saved) will re-readTruefrom the sourceconfig.jsonand re-strip. The model was trained against the saved stats, so switching the normalization mid-training only makes sense when followed by further training, not when loading purely for inference. Honored by every policy whosefrom_pretrained(or_load_as_safetensor) calls_strip_normalization_buffers_from_state_dict(). Defaults toFalse(no behaviour change).skip_input_resolution_check – Escape hatch for
validate_input_resolution(). WhenTrue, a mismatch between the policy’sresize_imgs_with_paddingand the(H, W)of the bound image features logs a loud warning instead of raising — even on the strict (training) path. Intended for deliberately resuming/finetuning a legacy checkpoint that was trained with the mismatch (i.e. with the policy silently letterboxing a second time insideprepare_images/prepare_videos); leaveFalsefor everything else. Eval-shaped policy construction never raises regardless of this flag (it warns), so plain evaluation of legacy checkpoints does not need it. Note thatTruepersists into theconfig.jsonof every checkpoint the run saves — coherent for resuming that same mismatch-trained lineage, but set it back tofalsewhen fine-tuning such a checkpoint against a new dataset mixture, or a fresh mismatch there will only warn instead of raising. Defaults toFalse.
- __init__(n_obs_steps: int = 1, normalization_mapping: dict[str, ~opentau.configs.types.NormalizationMode] = <factory>, input_features: dict[str, ~opentau.configs.types.PolicyFeature] = <factory>, output_features: dict[str, ~opentau.configs.types.PolicyFeature] = <factory>, device: str | None = None, use_amp: bool = False, use_torch_compile: bool = False, torch_compile_mode: str = 'default', pretrained_path: str | None = None, skip_normalization_weights: bool = False, skip_input_resolution_check: bool = False, save_normalization_stats: bool = True, dataset_names: list[str] | None = None, dataset_to_norm_index: dict[str, int] | None = None, cloud_vlm_latency_mean: float = 0.0, cloud_vlm_latency_std: float = 0.0, cloud_vlm_latency_lower: float = 0.0, cloud_vlm_latency_upper: float = 0.0, action_decoder_latency_mean: float = 0.0, action_decoder_latency_std: float = 0.0, action_decoder_latency_lower: float = 0.0, action_decoder_latency_upper: float = 0.0) None
- action_decoder_latency_lower: float = 0.0
- action_decoder_latency_mean: float = 0.0
- action_decoder_latency_std: float = 0.0
- action_decoder_latency_upper: float = 0.0
- abstract property action_delta_indices: list | None
Get indices for action delta features.
- Returns:
List of indices indicating which action features should be treated as deltas, or None if no delta features are used.
- property action_feature: PolicyFeature | None
Get the action feature from output features.
- Returns:
The PolicyFeature with type ACTION if found, or None otherwise.
- cloud_vlm_latency_lower: float = 0.0
- cloud_vlm_latency_mean: float = 0.0
- cloud_vlm_latency_std: float = 0.0
- cloud_vlm_latency_upper: float = 0.0
- dataset_names: list[str] | None = None
- dataset_to_norm_index: dict[str, int] | None = None
- device: str | None = None
- property env_state_feature: PolicyFeature | None
Get the environment state feature from input features.
- Returns:
The PolicyFeature with type ENV if found, or None otherwise.
- classmethod from_pretrained(pretrained_name_or_path: str | Path, *, force_download: bool = False, resume_download: bool | None = None, proxies: dict | None = None, token: str | bool | None = None, cache_dir: str | Path | None = None, local_files_only: bool = False, revision: str | None = None, **policy_kwargs) T[source]
Load a policy configuration from a pretrained model or local path.
- Parameters:
cls – The class to instantiate.
pretrained_name_or_path –
Can be either:
A string, the model id of a pretrained config hosted inside a model repo on huggingface.co.
A path to a directory containing a configuration file saved using the _save_pretrained method.
force_download – Whether to force (re-)downloading the config files and configuration from the HuggingFace Hub. Defaults to False.
resume_download – Whether to resume downloading the config files. Defaults to None.
proxies – Dictionary of proxies to use for requests. Defaults to None.
token – The token to use as HTTP bearer authorization. If True, will use the token generated when running huggingface-cli login. Defaults to None.
cache_dir – Path to a directory in which a downloaded pretrained model configuration should be cached. Defaults to None.
local_files_only – Whether to only look at local files (i.e., do not try to download the config). Defaults to False.
revision – The specific model version to use. It can be a branch name, a tag name, or a commit id. Defaults to None.
**policy_kwargs – Additional keyword arguments. May include ‘cli_overrides’ for command-line argument overrides.
- Returns:
An instance of the configuration class loaded from the specified path.
- Raises:
FileNotFoundError – If the configuration file is not found on the HuggingFace Hub or in the local path.
- abstract get_optimizer_preset() OptimizerConfig[source]
Get the default optimizer configuration for this policy.
- Returns:
An OptimizerConfig instance with default settings for this policy type.
- abstract get_scheduler_preset() LRSchedulerConfig | None[source]
Get the default learning rate scheduler configuration for this policy.
- Returns:
An LRSchedulerConfig instance with default settings for this policy type, or None if no scheduler should be used.
- property image_features: dict[str, PolicyFeature]
Get all visual/image features from input features.
- Returns:
Dictionary mapping feature names to PolicyFeature instances with type VISUAL.
- input_features: dict[str, PolicyFeature]
- property input_image_size: tuple[int, int] | None
(H, W)the vision tower will actually receive.This is
resize_imgs_with_paddingwhen the policy defines and sets it (the in-policy letterbox target), else the resolution of the bound image features (native pass-through), elseNonewhen neither is known (e.g. a bare config before feature binding).
- n_obs_steps: int = 1
- normalization_mapping: dict[str, NormalizationMode]
- abstract property observation_delta_indices: list | None
Get indices for observation delta features.
- Returns:
List of indices indicating which observation features should be treated as deltas, or None if no delta features are used.
- output_features: dict[str, PolicyFeature]
- pretrained_path: str | None = None
- abstract property reward_delta_indices: list | None
Get indices for reward delta features.
- Returns:
List of indices indicating which reward features should be treated as deltas, or None if no delta features are used.
- property robot_state_feature: PolicyFeature | None
Get the robot state feature from input features.
- Returns:
The PolicyFeature with type STATE if found, or None otherwise.
- save_normalization_stats: bool = True
- skip_input_resolution_check: bool = False
- skip_normalization_weights: bool = False
- torch_compile_mode: str = 'default'
- property type: str
Get the type name of this configuration.
- Returns:
The choice name of this configuration class.
- use_amp: bool = False
- use_torch_compile: bool = False
- abstract validate_features() None[source]
Validate that the feature configuration is correct.
This method should check that all required features are present and have valid configurations.
- Raises:
ValueError – If the feature configuration is invalid.
- validate_input_resolution(*, strict: bool) None[source]
Check
resize_imgs_with_paddingagainst the bound image features.The image features bound onto the config (from
TrainPipelineConfig.resolutionvia the dataset mixture at train time, or carried inside a checkpoint’sconfig.jsonat load time) are the(H, W)the policy actually receives. A differingresize_imgs_with_paddingmeans every frame gets silently letterboxed a second time inside the policy — downscaled and padded with black bars — which is almost never intended.With
resize_imgs_with_padding=None(native pass-through) there is no target to compare against, but the bound cameras must then agree with each other — with no in-policy resize step, a mixed-resolution camera set has no single geometry the vision tower could be built for, so that is flagged with the same strict/warn semantics.No-op when the policy has no
resize_imgs_with_paddingfield or no comparable image feature is bound.- Parameters:
strict –
Truefor training-shaped construction — raise on mismatch (unlessskip_input_resolution_check);Falsefor eval/inference — warn loudly but keep loading, so legacy checkpoints trained with the mismatch remain evaluable.- Raises:
ValueError – On mismatch when
strictisTrueandskip_input_resolution_checkisFalse.
- opentau.configs.policies.load_resolved_config_dict(source_path: str | Path) dict[source]
Resolve
$refincludes in a config JSON and return the resulting dict.Centralizes both the ref resolution and the top-level shape check so that every loader in this module fails consistently on a non-object root, and so that a single
from_pretrainedcall can resolve once and pass the dict to all downstream helpers (warnings, stripping) instead of re-walking the ref tree from disk for each.
- opentau.configs.policies.load_stripped_config_to_tempfile(source_path: str | Path) Path[source]
Read a config JSON, resolve
$refincludes, strip deprecated/removed fields in memory, write to a fresh temp file, and return its path. Does not mutatesource_path.Use this on incoming config files (HF Hub downloads, user-supplied paths) before handing them to
draccus.parse: HF cache paths are symlinks into a content-addressed blob store, so an in-place rewrite would corrupt the cache; user-supplied paths shouldn’t be mutated as a side effect of load.See
opentau.configs.refsfor$refsemantics.
- opentau.configs.policies.strip_deprecated_fields_from_json(path: Path) None[source]
Remove deprecated and removed fields from a config JSON file in-place.
Only safe to call on files we own (e.g. the JSON we just wrote inside a save directory). Do NOT use on user-supplied inputs or HF cache files — HF cache paths are symlinks into a content-addressed blob store, so an in-place rewrite mutates the blob and silently corrupts the cache. For incoming configs, use
load_stripped_config_to_tempfile()instead.
- opentau.configs.policies.warn_deprecated_latency_fields(config_path: str | Path) None[source]
Emit a deprecation warning if a config JSON file contains latency fields.
Checks both top-level fields and fields nested under a
"policy"key. Should be called before loading a config so users are aware the fields will be ignored. Resolves$refincludes so fields hidden behind a reference are still detected.
- opentau.configs.policies.warn_deprecated_latency_fields_from_dict(data: dict, config_path: str | Path) None[source]
Like
warn_deprecated_latency_fields()but operating on an already-resolved config dict, so callers that already loaded the dict don’t pay for a second$refwalk.config_pathis used only for the warning message.
- opentau.configs.policies.warn_removed_policy_fields(config_path: str | Path) None[source]
Emit a deprecation warning if a config JSON file contains removed fields.
Removed fields (e.g.
init_strategy) are stripped at load time so old saved configs continue to parse, but the user’s explicit choice is dropped on the floor — surface that with a warning so they know to re-save and update any downstream tooling that still emits the old key. Resolves$refincludes so fields hidden behind a reference are still detected.
- opentau.configs.policies.warn_removed_policy_fields_from_dict(data: dict, config_path: str | Path) None[source]
Like
warn_removed_policy_fields()but operating on an already-resolved config dict.config_pathis used only for the warning message.