2025-07-02 17:29:58 +02:00
|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
|
|
|
|
# Copyright 2025 The HuggingFace Inc. team. All rights reserved.
|
|
|
|
|
|
#
|
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
|
#
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
#
|
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
from __future__ import annotations
|
2025-07-02 15:31:15 +00:00
|
|
|
|
|
2025-07-03 14:11:28 +02:00
|
|
|
|
import importlib
|
2025-07-02 15:31:15 +00:00
|
|
|
|
import json
|
|
|
|
|
|
import os
|
2025-08-31 20:38:52 +02:00
|
|
|
|
from abc import ABC, abstractmethod
|
2025-07-21 14:54:31 +02:00
|
|
|
|
from collections.abc import Callable, Iterable, Sequence
|
2025-07-31 16:29:48 +02:00
|
|
|
|
from copy import deepcopy
|
2025-07-02 17:29:58 +02:00
|
|
|
|
from dataclasses import dataclass, field
|
2025-07-02 15:31:15 +00:00
|
|
|
|
from pathlib import Path
|
2025-09-02 12:57:14 +02:00
|
|
|
|
from typing import Any, Generic, TypedDict, TypeVar, cast
|
2025-07-02 15:31:15 +00:00
|
|
|
|
|
2025-07-02 17:29:58 +02:00
|
|
|
|
import torch
|
2025-07-02 15:31:15 +00:00
|
|
|
|
from huggingface_hub import ModelHubMixin, hf_hub_download
|
2025-07-22 14:35:34 +02:00
|
|
|
|
from huggingface_hub.errors import HfHubHTTPError
|
2025-07-02 15:31:15 +00:00
|
|
|
|
from safetensors.torch import load_file, save_file
|
2025-07-02 17:29:58 +02:00
|
|
|
|
|
2025-07-31 16:29:48 +02:00
|
|
|
|
from lerobot.configs.types import PolicyFeature
|
2025-07-22 11:03:28 +02:00
|
|
|
|
|
2025-09-03 12:28:40 +02:00
|
|
|
|
from .converters import batch_to_transition, create_transition, transition_to_batch
|
2025-09-02 15:33:38 +02:00
|
|
|
|
from .core import EnvTransition, TransitionKey
|
|
|
|
|
|
|
2025-09-02 12:57:14 +02:00
|
|
|
|
# Type variable for generic processor output type
|
|
|
|
|
|
TOutput = TypeVar("TOutput")
|
|
|
|
|
|
|
2025-07-02 17:29:58 +02:00
|
|
|
|
|
2025-07-03 14:11:28 +02:00
|
|
|
|
class ProcessorStepRegistry:
|
|
|
|
|
|
"""Registry for processor steps that enables saving/loading by name instead of module path."""
|
|
|
|
|
|
|
|
|
|
|
|
_registry: dict[str, type] = {}
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
def register(cls, name: str = None):
|
|
|
|
|
|
"""Decorator to register a processor step class.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
name: Optional registration name. If not provided, uses class name.
|
|
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
@ProcessorStepRegistry.register("adaptive_normalizer")
|
|
|
|
|
|
class AdaptiveObservationNormalizer:
|
|
|
|
|
|
...
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def decorator(step_class: type) -> type:
|
|
|
|
|
|
registration_name = name if name is not None else step_class.__name__
|
|
|
|
|
|
|
|
|
|
|
|
if registration_name in cls._registry:
|
|
|
|
|
|
raise ValueError(
|
|
|
|
|
|
f"Processor step '{registration_name}' is already registered. "
|
|
|
|
|
|
f"Use a different name or unregister the existing one first."
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
cls._registry[registration_name] = step_class
|
|
|
|
|
|
# Store the registration name on the class for later reference
|
|
|
|
|
|
step_class._registry_name = registration_name
|
|
|
|
|
|
return step_class
|
|
|
|
|
|
|
|
|
|
|
|
return decorator
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
def get(cls, name: str) -> type:
|
|
|
|
|
|
"""Get a registered processor step class by name.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
name: The registration name of the step.
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
The registered step class.
|
|
|
|
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
|
|
KeyError: If the step is not registered.
|
|
|
|
|
|
"""
|
|
|
|
|
|
if name not in cls._registry:
|
|
|
|
|
|
available = list(cls._registry.keys())
|
|
|
|
|
|
raise KeyError(
|
|
|
|
|
|
f"Processor step '{name}' not found in registry. "
|
|
|
|
|
|
f"Available steps: {available}. "
|
|
|
|
|
|
f"Make sure the step is registered using @ProcessorStepRegistry.register()"
|
|
|
|
|
|
)
|
|
|
|
|
|
return cls._registry[name]
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
def unregister(cls, name: str) -> None:
|
|
|
|
|
|
"""Remove a step from the registry."""
|
|
|
|
|
|
cls._registry.pop(name, None)
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
def list(cls) -> list[str]:
|
|
|
|
|
|
"""List all registered step names."""
|
|
|
|
|
|
return list(cls._registry.keys())
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
def clear(cls) -> None:
|
|
|
|
|
|
"""Clear all registrations."""
|
|
|
|
|
|
cls._registry.clear()
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-31 20:38:52 +02:00
|
|
|
|
class ProcessorStep(ABC):
|
2025-07-03 14:11:28 +02:00
|
|
|
|
"""Structural typing interface for a single processor step.
|
2025-07-02 15:31:15 +00:00
|
|
|
|
|
2025-08-06 14:00:13 +02:00
|
|
|
|
A step is any callable accepting a full `EnvTransition` dict and
|
|
|
|
|
|
returning a (possibly modified) dict of the same structure. Implementers
|
2025-07-02 17:29:58 +02:00
|
|
|
|
are encouraged—but not required—to expose the optional helper methods
|
2025-09-03 17:13:16 +02:00
|
|
|
|
listed below. When present, these hooks let `DataProcessorPipeline`
|
2025-07-02 17:29:58 +02:00
|
|
|
|
automatically serialise the step's configuration and learnable state using
|
|
|
|
|
|
a safe-to-share JSON + SafeTensors format.
|
2025-07-02 15:31:15 +00:00
|
|
|
|
|
2025-07-31 16:29:48 +02:00
|
|
|
|
|
|
|
|
|
|
**Required**:
|
|
|
|
|
|
- ``__call__(transition: EnvTransition) -> EnvTransition``
|
|
|
|
|
|
|
2025-07-02 17:29:58 +02:00
|
|
|
|
Optional helper protocol:
|
2025-07-09 18:20:43 +02:00
|
|
|
|
* ``get_config() -> dict[str, Any]`` – User-defined JSON-serializable
|
2025-07-02 17:29:58 +02:00
|
|
|
|
configuration and state. YOU decide what to save here. This is where all
|
|
|
|
|
|
non-tensor state goes (e.g., name, counter, threshold, window_size).
|
|
|
|
|
|
The config dict will be passed to your class constructor when loading.
|
2025-07-09 18:20:43 +02:00
|
|
|
|
* ``state_dict() -> dict[str, torch.Tensor]`` – PyTorch tensor state ONLY.
|
2025-07-02 17:29:58 +02:00
|
|
|
|
This is exclusively for torch.Tensor objects (e.g., learned weights,
|
|
|
|
|
|
running statistics as tensors). Never put simple Python types here.
|
|
|
|
|
|
* ``load_state_dict(state)`` – Inverse of ``state_dict``. Receives a dict
|
|
|
|
|
|
containing torch tensors only.
|
|
|
|
|
|
* ``reset()`` – Clear internal buffers at episode boundaries.
|
Integrate pipeline and add phone teleop (#1681)
* Add normalization processor and related components
- Introduced `NormalizationProcessor` to handle both observation normalization and action unnormalization.
- Added `ObservationNormalizer` and `ActionUnnormalizer` classes for specific normalization tasks.
- Updated `__init__.py` to include the new `NormalizationProcessor` in the module exports.
- Enhanced `ObservationProcessor` with registration in the `ProcessorStepRegistry` for better modularity.
- Created `RenameProcessor` for renaming keys in observations, improving flexibility in data processing.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Enhance processing architecture with new components
- Added `RenameProcessor` to facilitate key renaming in observations, improving data handling flexibility.
- Updated `__init__.py` to include `RenameProcessor` in module exports.
- Refactored `NormalizationProcessor` and `ObservationNormalizer` to use `rsplit` for better key handling.
- Introduced comprehensive tests for `NormalizationProcessor` and `RenameProcessor` to ensure functionality and robustness.
* chore (docs): add docstring for processor
* fix (test): test factory
* fix(test): policies
* Update tests/processor/test_observation_processor.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
* chore(test): add suggestion made by copilot regarding numpy test
* fix(test): import issue
* Refactor normalization components and update tests
- Renamed `ObservationNormalizer` to `NormalizerProcessor` and `ActionUnnormalizer` to `UnnormalizerProcessor` for clarity.
- Consolidated normalization logic for both observations and actions into `NormalizerProcessor` and `UnnormalizerProcessor`.
- Updated tests to reflect the new class names and ensure proper functionality of normalization and unnormalization processes.
- Enhanced handling of missing statistics in normalization processes.
* chore (docstrin):Improve docstring for NormalizerProcessor
* feat (device processor): Implement device processor
* chore (batch handling): Enhance processing components with batch conversion utilities
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix(test): linting issue
* chore (output format): improves output format
* chore (type): add typing for multiprocess envs
* feat (overrides): Implement support for loading processors with parameter overrides
- Added the ability to provide non-serializable objects when loading processors from saved configurations using the `overrides` parameter.
- Enhanced error handling for invalid override keys and instantiation errors.
- Updated documentation and examples to illustrate the usage of overrides for both registered and unregistered steps.
- Added comprehensive tests to validate the new functionality and ensure backward compatibility.
* chore(normalization): addressing comments from copilot
* chore(learner): nit comment from copilot
* feat(pipeline): Enhance step_through method to support both tuple and dict inputs
* refactor(pipeline): Simplify observation and padding data handling in batch transitions
* Apply suggestions from code review
Co-authored-by: Simon Alibert <75076266+aliberts@users.noreply.github.com>
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Introduce ComplementaryDataProcessor for handling complementary data in transitions
* fix(ci): temporary fix on dataset deps version
* feat(processors): Introduce processors for various policy types
- Added `make_processor` function to create processor instances for different policy types, including `tdmpc`, `diffusion`, `act`, `vqbet`, `pi0`, `pi0fast`, `sac`, and `reward_classifier`.
- Implemented corresponding processor files for each policy type, encapsulating normalization and unnormalization steps.
- Updated existing policies to remove direct normalization dependencies, enhancing modularity and clarity.
- Enhanced test coverage to validate the integration of new processors with existing policy configurations.
* refactor(learner): Remove normalization from cached image features retrieval
- Simplified the retrieval of observation features by removing the normalization step from the `get_cached_image_features` method calls.
- This change enhances clarity and aligns with the recent updates to policy processors.
* refactor(policies): Remove unnormalization step from action predictions
- Eliminated the unnormalization of actions in both `TDMPCPolicy` and `VQBeTPolicy` classes to streamline action prediction.
- This change improves code clarity and aligns with recent updates to policy processors.
* feat(train): Integrate preprocessor into training pipeline
* refactor(train): Update preprocessor initialization to include dataset statistics
* refactor(policies): Enhance processor creation and add NaN detection hook
* refactor(train): Update memory pinning logic for mps compatibility
* feat: initial commit phone teleop
* ugly delta control
* use quaternion
* Refactor observation preprocessing to use a modular pipeline system
- Introduced `RobotPipeline` and `ObservationProcessor` for handling observation transformations.
- Updated `preprocess_observation` to maintain backward compatibility while leveraging the new pipeline.
- Added tests for the new processing components and ensured they match the original functionality.
- Removed hardcoded logic in favor of a more flexible, composable architecture.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor observation processing and improve modularity
- Updated `ObservationProcessor` to enhance the modular design for processing observations.
- Cleaned up imports and improved code readability by removing unnecessary lines and comments.
- Ensured backward compatibility while integrating new processing components.
- Added tests to validate the functionality of the updated processing architecture.
* Remove redundant tests for None observation and serialization methods in `test_observation_processor.py` to streamline the test suite and improve maintainability.
* Refactor processing architecture to use RobotProcessor
- Replaced instances of RobotPipeline with RobotProcessor across the codebase for improved modularity and clarity.
- Introduced ProcessorStepRegistry for better management of processing steps.
- Updated relevant documentation and tests to reflect the new processing structure.
- Enhanced the save/load functionality to support the new processor design.
- Added a model card template for RobotProcessor to facilitate sharing and documentation.
* Add RobotProcessor tutorial to documentation
- Introduced a new tutorial on using RobotProcessor for preprocessing robot data.
- Added a section in the table of contents for easy navigation to the new tutorial.
- The tutorial covers key concepts, real-world scenarios, and practical examples for effective use of the RobotProcessor pipeline.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add normalization processor and related components
- Introduced `NormalizationProcessor` to handle both observation normalization and action unnormalization.
- Added `ObservationNormalizer` and `ActionUnnormalizer` classes for specific normalization tasks.
- Updated `__init__.py` to include the new `NormalizationProcessor` in the module exports.
- Enhanced `ObservationProcessor` with registration in the `ProcessorStepRegistry` for better modularity.
- Created `RenameProcessor` for renaming keys in observations, improving flexibility in data processing.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Enhance processing architecture with new components
- Added `RenameProcessor` to facilitate key renaming in observations, improving data handling flexibility.
- Updated `__init__.py` to include `RenameProcessor` in module exports.
- Refactored `NormalizationProcessor` and `ObservationNormalizer` to use `rsplit` for better key handling.
- Introduced comprehensive tests for `NormalizationProcessor` and `RenameProcessor` to ensure functionality and robustness.
* chore (docs): add docstring for processor
* fix (test): test factory
* fix(test): policies
* Update tests/processor/test_observation_processor.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
* chore(test): add suggestion made by copilot regarding numpy test
* fix(test): import issue
* Refactor normalization components and update tests
- Renamed `ObservationNormalizer` to `NormalizerProcessor` and `ActionUnnormalizer` to `UnnormalizerProcessor` for clarity.
- Consolidated normalization logic for both observations and actions into `NormalizerProcessor` and `UnnormalizerProcessor`.
- Updated tests to reflect the new class names and ensure proper functionality of normalization and unnormalization processes.
- Enhanced handling of missing statistics in normalization processes.
* chore (docstrin):Improve docstring for NormalizerProcessor
* feat (device processor): Implement device processor
* chore (batch handling): Enhance processing components with batch conversion utilities
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix(test): linting issue
* chore (output format): improves output format
* chore (type): add typing for multiprocess envs
* feat (overrides): Implement support for loading processors with parameter overrides
- Added the ability to provide non-serializable objects when loading processors from saved configurations using the `overrides` parameter.
- Enhanced error handling for invalid override keys and instantiation errors.
- Updated documentation and examples to illustrate the usage of overrides for both registered and unregistered steps.
- Added comprehensive tests to validate the new functionality and ensure backward compatibility.
* chore(normalization): addressing comments from copilot
* chore(learner): nit comment from copilot
* feat(pipeline): Enhance step_through method to support both tuple and dict inputs
* refactor(pipeline): Simplify observation and padding data handling in batch transitions
* Apply suggestions from code review
Co-authored-by: Simon Alibert <75076266+aliberts@users.noreply.github.com>
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Introduce ComplementaryDataProcessor for handling complementary data in transitions
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Transition from tuple to dictionary format for EnvTransition
- Updated the EnvTransition structure to use a dictionary format instead of a tuple, enhancing readability and maintainability.
- Replaced instances of TransitionIndex with TransitionKey for accessing transition components.
- Adjusted related processing functions and tests to accommodate the new dictionary format, ensuring consistent handling of transitions across the codebase.
* refactor(observation_processor): Improve observation processing by using constants and simplifying pixel handling
- Introduced constants for observation keys to enhance readability.
- Streamlined the handling of the "pixels" key by copying observations first and processing images more clearly.
- Updated the environment state and agent position assignments to use the new constants, improving maintainability.
* feat(pipeline): Add hook unregistration functionality and enhance documentation
- Implemented methods to unregister before, after, and reset hooks in the RobotProcessor class, allowing for more flexible hook management.
- Enhanced documentation to clarify hook execution semantics and the implications of modifying transitions within hooks.
- Added comprehensive tests to verify the correct behavior of hook registration and unregistration, including error handling for non-existent hooks.
* refactor(pipeline): Clarify hook behavior and improve documentation
- Updated the RobotProcessor class to ensure hooks are strictly for observation and do not modify transitions, enhancing clarity and maintainability.
- Refactored hook registration methods to reflect the new behavior, ensuring they accept only functions that do not return modified transitions.
- Enhanced documentation to clearly outline the purpose of hooks and their execution semantics.
- Added tests to verify that hooks are not executed during the step_through method while ensuring they function correctly during the __call__ method.
* feat(pipeline): Add __repr__ method to RobotProcessor for improved readability
- Implemented a __repr__ method in the RobotProcessor class to provide a clear string representation of the processor, including step names and optional parameters like name and seed.
- Added comprehensive tests to validate the __repr__ output for various scenarios, including empty processors, single and multiple steps, custom names, and seed values.
- Ensured that the representation handles long lists of steps with truncation for better readability.
* chore(pipeline): Move _CFG_NAME along other class member
* refactor(pipeline): Utilize get_safe_torch_device for device assignment
- Replaced direct torch.device instantiation with get_safe_torch_device to ensure safe device handling.
- This change enhances code readability and maintains consistency in device management across the RobotProcessor class.
* refactor(pipeline): Enhance state filename generation and profiling method
- Updated state filename generation to use the registry name when available, improving clarity in saved files.
- Modified the profile_steps method to include a warmup_runs parameter, allowing for more controlled performance profiling.
- Ensured consistent conditions during profiling by deep copying transitions for each run, enhancing accuracy in timing results.
* chore(doc): address pip install commant lerobot that not exist yet
* feat(pipeline): Enhance configuration filename handling and state file naming
- Introduced support for custom configuration filenames in the `save_pretrained` method, allowing users to specify a filename instead of the default.
- Improved state file naming to include step indices, preventing conflicts when multiple processors of the same type are saved.
- Added automatic detection for configuration files when loading from a directory, with error handling for multiple files.
- Updated tests to validate new features, including custom filenames and automatic config detection.
* refactor(pipeline): Improve state file naming conventions for clarity and uniqueness
- Enhanced state file naming to include the processor's sanitized name, ensuring uniqueness when multiple processors are saved in the same directory.
- Updated tests to reflect changes in state file naming, verifying that filenames now include the processor name and step indices to prevent conflicts.
- Added a new test to validate state file naming when using multiple processors, ensuring distinct filenames for each processor's state files.
* docs(pipeline): Add clarification for repo name sanitization process
* feat(processors): Introduce processors for various policy types
- Added `make_processor` function to create processor instances for different policy types, including `tdmpc`, `diffusion`, `act`, `vqbet`, `pi0`, `pi0fast`, `sac`, and `reward_classifier`.
- Implemented corresponding processor files for each policy type, encapsulating normalization and unnormalization steps.
- Updated existing policies to remove direct normalization dependencies, enhancing modularity and clarity.
- Enhanced test coverage to validate the integration of new processors with existing policy configurations.
* refactor(learner): Remove normalization from cached image features retrieval
- Simplified the retrieval of observation features by removing the normalization step from the `get_cached_image_features` method calls.
- This change enhances clarity and aligns with the recent updates to policy processors.
* refactor(policies): Remove unnormalization step from action predictions
- Eliminated the unnormalization of actions in both `TDMPCPolicy` and `VQBeTPolicy` classes to streamline action prediction.
- This change improves code clarity and aligns with recent updates to policy processors.
* feat(train): Integrate preprocessor into training pipeline
* refactor(train): Update preprocessor initialization to include dataset statistics
* refactor(policies): Enhance processor creation and add NaN detection hook
* feat(record): Integrate RobotProcessor into recording loop and update policy handling
- Added support for RobotProcessor in the record_loop function to enhance data processing capabilities.
- Updated the logic to reset both policy and processor when provided, ensuring proper state management.
- Modified action prediction to utilize the processor, improving the overall functionality of the recording process.
- Adjusted the save_checkpoint function to include preprocessor state saving, enhancing checkpointing capabilities.
* feat(migration): Add script for migrating policy models with normalization layers
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(migrate): Enhance migration script to create preprocessor and postprocessor for policy models
- Updated the migration script to generate both a preprocessor and a postprocessor, improving the handling of normalization for training and inference.
- Added functionality to convert features to PolicyFeature objects, ensuring compatibility with the new processor architecture.
- Refined the extraction and removal of normalization statistics and layers, streamlining the migration process.
- Improved error handling for missing mandatory configuration fields during model instantiation.
* feat(migrate): Add model card generation and saving to migration script
- Implemented functionality to generate and save a model card for the migrated model, including metadata such as dataset repository ID, license, and tags.
- Enhanced the script to push the model card to the hub if requested, improving model documentation and accessibility.
- Refactored the saving process to ensure the model card is saved locally and uploaded correctly when pushing to the hub.
* feat(processor): Introduce ToBatchProcessor for handling observation batching
- Added ToBatchProcessor to ensure observations have proper batch dimensions for model processing.
- Implemented functionality to add batch dimensions to state and image observations as needed.
- Created comprehensive unit tests to validate the processor's behavior with various tensor dimensions and types.
- Ensured compatibility with existing transition keys and maintained the integrity of non-observation data.
* feat(processors): Add ToBatchProcessor to multiple policy processors
- Integrated ToBatchProcessor into various policy processors to handle observation batching.
- Updated make functions for act, diffusion, pi0, pi0fast, sac, smolvla, tdmpc, and vqbet processors to include the new batching functionality.
- Ensured consistency across all processor implementations for improved data handling.
* refactor(factory): Remove unused imports and NaN detection hook from processor creation
* feat(batch_processor): Enhance ToBatchProcessor to handle action batching
- Updated ToBatchProcessor to add batch dimensions to actions in addition to observations.
- Implemented separate methods for processing observations and actions, improving code readability.
- Added comprehensive unit tests to validate action batching functionality across various tensor dimensions and types.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(factory): Enhance make_processor to support preprocessor and postprocessor configuration
- Introduced ProcessorConfigKwargs TypedDict for better type safety in processor configuration.
- Updated make_processor to accept preprocessor and postprocessor configuration filenames, improving flexibility in processor instantiation.
- Refactored the loading of pretrained processors to utilize the new configuration options.
* refactor(factory): Clean up imports in factory.py
- Removed unused import of IdentityProcessor to streamline the code.
* feat(migrate): Extend load_model_from_hub to include train configuration
- Updated load_model_from_hub to return the train configuration alongside the model state_dict and config.
- Modified main function to handle the additional train configuration when loading models from both the hub and local paths.
- Adjusted dataset_repo_id extraction to utilize the train configuration for improved accuracy.
* refactor(record): Rename processor parameters and update processing logic
- Renamed `processor` to `preprocessor` and added `postprocessor` parameter for clarity.
- Updated the `record_loop` and `predict_action` functions to utilize the new preprocessor and postprocessor, enhancing the processing flow.
- Ensured compatibility with existing functionality while improving code readability.
* feat(batch_processor): Add task field processing to ToBatchProcessor
- Enhanced ToBatchProcessor to wrap string tasks in a list, adding batch dimensions for compatibility with model inference.
- Implemented a new method for processing complementary data, ensuring that task values are correctly handled as either strings or lists of strings.
- Added comprehensive unit tests to validate task processing, including edge cases and in-place mutation of complementary data.
* feat(normalization): Implement IDENTITY mode for normalization and unnormalization
- Enhanced NormalizerProcessor and UnnormalizerProcessor to support IDENTITY mode, allowing features to bypass normalization when specified.
- Updated processing logic to check normalization modes and handle missing statistics gracefully.
- Added comprehensive unit tests to validate IDENTITY mode functionality for both observations and actions, ensuring correct behavior across various scenarios.
- Improved error handling for unsupported normalization modes.
* fix(rebase): remove residual normalization layer:
* refactor(diffusion): remove normalization layer from input processing
* Add debug + calib
* cleanup
* Add pipeline
* fix int
* Add record example
* nit
* Add feature contract to pipelinestep and pipeline
* Add tests
* Add processor tests
* PR feedback
* encorperate pr feedback
* type in doc
* oops
* cleaned up steps and integrated pipeline with feature_contract
* refactor steps and robot to pipeline
* cleanup pipeline
* cleanup code further
* make it run
* feat(processors): Introduce processors for various policy types
- Added `make_processor` function to create processor instances for different policy types, including `tdmpc`, `diffusion`, `act`, `vqbet`, `pi0`, `pi0fast`, `sac`, and `reward_classifier`.
- Implemented corresponding processor files for each policy type, encapsulating normalization and unnormalization steps.
- Updated existing policies to remove direct normalization dependencies, enhancing modularity and clarity.
- Enhanced test coverage to validate the integration of new processors with existing policy configurations.
* refactor(learner): Remove normalization from cached image features retrieval
- Simplified the retrieval of observation features by removing the normalization step from the `get_cached_image_features` method calls.
- This change enhances clarity and aligns with the recent updates to policy processors.
* refactor(policies): Remove unnormalization step from action predictions
- Eliminated the unnormalization of actions in both `TDMPCPolicy` and `VQBeTPolicy` classes to streamline action prediction.
- This change improves code clarity and aligns with recent updates to policy processors.
* feat(train): Integrate preprocessor into training pipeline
* refactor(train): Update preprocessor initialization to include dataset statistics
* refactor(policies): Enhance processor creation and add NaN detection hook
* feat(record): Integrate RobotProcessor into recording loop and update policy handling
- Added support for RobotProcessor in the record_loop function to enhance data processing capabilities.
- Updated the logic to reset both policy and processor when provided, ensuring proper state management.
- Modified action prediction to utilize the processor, improving the overall functionality of the recording process.
- Adjusted the save_checkpoint function to include preprocessor state saving, enhancing checkpointing capabilities.
* feat(migration): Add script for migrating policy models with normalization layers
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(migrate): Enhance migration script to create preprocessor and postprocessor for policy models
- Updated the migration script to generate both a preprocessor and a postprocessor, improving the handling of normalization for training and inference.
- Added functionality to convert features to PolicyFeature objects, ensuring compatibility with the new processor architecture.
- Refined the extraction and removal of normalization statistics and layers, streamlining the migration process.
- Improved error handling for missing mandatory configuration fields during model instantiation.
* feat(migrate): Add model card generation and saving to migration script
- Implemented functionality to generate and save a model card for the migrated model, including metadata such as dataset repository ID, license, and tags.
- Enhanced the script to push the model card to the hub if requested, improving model documentation and accessibility.
- Refactored the saving process to ensure the model card is saved locally and uploaded correctly when pushing to the hub.
* feat(processor): Introduce ToBatchProcessor for handling observation batching
- Added ToBatchProcessor to ensure observations have proper batch dimensions for model processing.
- Implemented functionality to add batch dimensions to state and image observations as needed.
- Created comprehensive unit tests to validate the processor's behavior with various tensor dimensions and types.
- Ensured compatibility with existing transition keys and maintained the integrity of non-observation data.
* feat(processors): Add ToBatchProcessor to multiple policy processors
- Integrated ToBatchProcessor into various policy processors to handle observation batching.
- Updated make functions for act, diffusion, pi0, pi0fast, sac, smolvla, tdmpc, and vqbet processors to include the new batching functionality.
- Ensured consistency across all processor implementations for improved data handling.
* refactor(factory): Remove unused imports and NaN detection hook from processor creation
* feat(batch_processor): Enhance ToBatchProcessor to handle action batching
- Updated ToBatchProcessor to add batch dimensions to actions in addition to observations.
- Implemented separate methods for processing observations and actions, improving code readability.
- Added comprehensive unit tests to validate action batching functionality across various tensor dimensions and types.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(factory): Enhance make_processor to support preprocessor and postprocessor configuration
- Introduced ProcessorConfigKwargs TypedDict for better type safety in processor configuration.
- Updated make_processor to accept preprocessor and postprocessor configuration filenames, improving flexibility in processor instantiation.
- Refactored the loading of pretrained processors to utilize the new configuration options.
* refactor(factory): Clean up imports in factory.py
- Removed unused import of IdentityProcessor to streamline the code.
* feat(migrate): Extend load_model_from_hub to include train configuration
- Updated load_model_from_hub to return the train configuration alongside the model state_dict and config.
- Modified main function to handle the additional train configuration when loading models from both the hub and local paths.
- Adjusted dataset_repo_id extraction to utilize the train configuration for improved accuracy.
* refactor(record): Rename processor parameters and update processing logic
- Renamed `processor` to `preprocessor` and added `postprocessor` parameter for clarity.
- Updated the `record_loop` and `predict_action` functions to utilize the new preprocessor and postprocessor, enhancing the processing flow.
- Ensured compatibility with existing functionality while improving code readability.
* feat(batch_processor): Add task field processing to ToBatchProcessor
- Enhanced ToBatchProcessor to wrap string tasks in a list, adding batch dimensions for compatibility with model inference.
- Implemented a new method for processing complementary data, ensuring that task values are correctly handled as either strings or lists of strings.
- Added comprehensive unit tests to validate task processing, including edge cases and in-place mutation of complementary data.
* feat(normalization): Implement IDENTITY mode for normalization and unnormalization
- Enhanced NormalizerProcessor and UnnormalizerProcessor to support IDENTITY mode, allowing features to bypass normalization when specified.
- Updated processing logic to check normalization modes and handle missing statistics gracefully.
- Added comprehensive unit tests to validate IDENTITY mode functionality for both observations and actions, ensuring correct behavior across various scenarios.
- Improved error handling for unsupported normalization modes.
* fix(rebase): remove residual normalization layer:
* refactor(diffusion): remove normalization layer from input processing
* refactor(normalization): Remove unused state dict transformation methods and streamline imports
- Eliminated the _transform_state_dict_keys and _load_as_safetensor methods from PI0Policy, simplifying the model loading process.
- Cleaned up imports in modeling_pi0.py by removing log_model_loading_keys and init_logging.
- Updated TDMPCPolicy and VQBeTPolicy to handle action removal from batches during offline evaluation.
- Introduced hotswap_stats function in normalize_processor.py to update normalization statistics dynamically, with corresponding tests to ensure functionality.
* refactor(normalization): Clean up imports in normalize_processor.py
* feat(batch_processor): Add feature_contract method to ToBatchProcessor
- Introduced feature_contract method that returns features without modification, maintaining the no-op behavior of the processor.
- This addition enhances the flexibility of the ToBatchProcessor for future feature processing needs.
* fix(dependencies): Update transformers dependency constraint to allow only versions up to 4.52.0
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(tokenizer): Introduce TokenizerProcessor for text tokenization
- Added TokenizerProcessor class to handle tokenization of task strings using Hugging Face's AutoTokenizer.
- Supports both string and list inputs, with customizable parameters for task key, output key, and tokenization settings.
- Implemented comprehensive unit tests to validate functionality, including handling of various input scenarios and integration with RobotProcessor.
- Updated types.py to include LANGUAGE feature type and modified __init__.py to register the new processor.
* feat(language): Enhance language processing in TokenizerProcessor
- Added OBS_LANGUAGE constant to define the observation language key.
- Updated TokenizerProcessor to store tokenized task data in the observation dictionary, ensuring compatibility with the new language feature.
- Introduced Pi0NewLineProcessor to append newlines to tasks for proper tokenization.
- Modified tests to validate the integration of language tokens and attention masks in the observation structure.
* feat(tokenizer): Add padding configuration to TokenizerProcessor
- Introduced `padding_side` parameter to the TokenizerProcessor for customizable padding direction.
- Updated the `make_pi0_processor` function to include the new padding configuration.
- Enhanced unit tests to validate the functionality of the `padding_side` parameter in various scenarios.
* feat(processor): Add state management methods to Pi0NewLineProcessor
* feat(normalization): Track normalization and unnormalization info in complementary data
- Updated NormalizerProcessor and UnnormalizerProcessor to accept additional parameters for tracking normalization modes.
- Enhanced the __call__ methods to store normalization and unnormalization information in the complementary data of transitions.
- Added unit tests to verify the correct tracking of normalization info, including scenarios with missing stats and selective normalization keys.
* feat(factory): Add preprocessor and postprocessor overrides to ProcessorConfigKwargs
- Updated ProcessorConfigKwargs to include optional overrides for preprocessor and postprocessor configurations.
- Enhanced the make_processor function to utilize the new overrides, allowing for more flexible processor initialization.
* feat(processors): Integrate RenameProcessor into various processor configurations
- Added RenameProcessor to the input steps of multiple processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Consolidated normalization features from input and output into a single NormalizerProcessor for improved efficiency.
- Updated the input steps to ensure compatibility with the new RenameProcessor integration.
* Do some todos and cleanup
* change feature_contract to dataset_features
* use one method for conversion pipeline output to add_frame dict and use base processors where possible
* Add back in and use record_loop
* update todo
* rename to_dataset_frame
* feat(smolvla): Refactor language processing and introduce new line processor (#1658)
- Removed the prepare_language method and directly accessed language tokens and masks from the batch using the OBS_LANGUAGE constant.
- Added SmolVLANewLineProcessor to ensure tasks end with a newline, enhancing tokenization compatibility.
- Updated the make_smolvla_processor function to include the new line processor and tokenizer processor for improved input handling.
* feat(processors): Integrate DeviceProcessor into multiple processor configurations
- Added DeviceProcessor to the input and output steps of various processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_pi0fast_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Enhanced the DeviceProcessor class with state management methods and ensured compatibility with existing processor pipelines.
- Introduced unit tests for DeviceProcessor to validate functionality across different scenarios, including CPU and CUDA operations.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* fix reference frame
* refactor(pipeline): Remove to() method for device management
- Eliminated the to() method from RobotProcessor, which was responsible for moving tensor states to specified devices.
- Removed associated unit tests that validated the functionality of the to() method across various scenarios.
- Streamlined the pipeline code by focusing on other device management strategies.
* feat(processor): Enhance DeviceProcessor with float dtype conversion
- Added support for optional float dtype conversion in DeviceProcessor, allowing tensors to be converted to specified floating-point types while preserving non-float types.
- Implemented validation for float dtype input and updated the processor's configuration methods to include float dtype.
- Refactored tensor processing logic to streamline device movement and dtype conversion.
- Introduced comprehensive unit tests to validate the new float dtype functionality across various scenarios.
* update data visualization
* update teleop example
* fix record bugs
* Add replay
* Not code
* feature(pipeline): port tokenizer pipeline for VLA (#1645)
* feat(tokenizer): Introduce TokenizerProcessor for text tokenization
- Added TokenizerProcessor class to handle tokenization of task strings using Hugging Face's AutoTokenizer.
- Supports both string and list inputs, with customizable parameters for task key, output key, and tokenization settings.
- Implemented comprehensive unit tests to validate functionality, including handling of various input scenarios and integration with RobotProcessor.
- Updated types.py to include LANGUAGE feature type and modified __init__.py to register the new processor.
* feat(language): Enhance language processing in TokenizerProcessor
- Added OBS_LANGUAGE constant to define the observation language key.
- Updated TokenizerProcessor to store tokenized task data in the observation dictionary, ensuring compatibility with the new language feature.
- Introduced Pi0NewLineProcessor to append newlines to tasks for proper tokenization.
- Modified tests to validate the integration of language tokens and attention masks in the observation structure.
* feat(tokenizer): Add padding configuration to TokenizerProcessor
- Introduced `padding_side` parameter to the TokenizerProcessor for customizable padding direction.
- Updated the `make_pi0_processor` function to include the new padding configuration.
- Enhanced unit tests to validate the functionality of the `padding_side` parameter in various scenarios.
* feat(processor): Add state management methods to Pi0NewLineProcessor
* feat(normalization): Track normalization and unnormalization info in complementary data
- Updated NormalizerProcessor and UnnormalizerProcessor to accept additional parameters for tracking normalization modes.
- Enhanced the __call__ methods to store normalization and unnormalization information in the complementary data of transitions.
- Added unit tests to verify the correct tracking of normalization info, including scenarios with missing stats and selective normalization keys.
* feat(factory): Add preprocessor and postprocessor overrides to ProcessorConfigKwargs
- Updated ProcessorConfigKwargs to include optional overrides for preprocessor and postprocessor configurations.
- Enhanced the make_processor function to utilize the new overrides, allowing for more flexible processor initialization.
* feat(processors): Integrate RenameProcessor into various processor configurations
- Added RenameProcessor to the input steps of multiple processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Consolidated normalization features from input and output into a single NormalizerProcessor for improved efficiency.
- Updated the input steps to ensure compatibility with the new RenameProcessor integration.
* feat(smolvla): Refactor language processing and introduce new line processor (#1658)
- Removed the prepare_language method and directly accessed language tokens and masks from the batch using the OBS_LANGUAGE constant.
- Added SmolVLANewLineProcessor to ensure tasks end with a newline, enhancing tokenization compatibility.
- Updated the make_smolvla_processor function to include the new line processor and tokenizer processor for improved input handling.
* feture(policies): add device processor (#1659)
* feat(processors): Integrate DeviceProcessor into multiple processor configurations
- Added DeviceProcessor to the input and output steps of various processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_pi0fast_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Enhanced the DeviceProcessor class with state management methods and ensured compatibility with existing processor pipelines.
- Introduced unit tests for DeviceProcessor to validate functionality across different scenarios, including CPU and CUDA operations.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Remove to() method for device management
- Eliminated the to() method from RobotProcessor, which was responsible for moving tensor states to specified devices.
- Removed associated unit tests that validated the functionality of the to() method across various scenarios.
- Streamlined the pipeline code by focusing on other device management strategies.
* feat(processor): Enhance DeviceProcessor with float dtype conversion
- Added support for optional float dtype conversion in DeviceProcessor, allowing tensors to be converted to specified floating-point types while preserving non-float types.
- Implemented validation for float dtype input and updated the processor's configuration methods to include float dtype.
- Refactored tensor processing logic to streamline device movement and dtype conversion.
- Introduced comprehensive unit tests to validate the new float dtype functionality across various scenarios.
* feat(policies): Add new line processors and update module exports
* feat(processor): Enhance batch and device processors to handle index and task_index fields
- Added logic to ToBatchProcessor for unsqueezing 0D tensors for index and task_index fields, ensuring they are processed as 1D tensors.
- Updated DeviceProcessor to process index and task_index fields in complementary data, preserving their tensor types and ensuring non-tensor fields remain unchanged.
- Enhanced unit tests to validate the correct handling of index and task_index fields across various scenarios, including device compatibility and dtype preservation.
* Add eval script
* fix `q_curr` in InverseKinematicsEEToJoints to the IK solution
* feat(processors): Introduce processors for various policy types
- Added `make_processor` function to create processor instances for different policy types, including `tdmpc`, `diffusion`, `act`, `vqbet`, `pi0`, `pi0fast`, `sac`, and `reward_classifier`.
- Implemented corresponding processor files for each policy type, encapsulating normalization and unnormalization steps.
- Updated existing policies to remove direct normalization dependencies, enhancing modularity and clarity.
- Enhanced test coverage to validate the integration of new processors with existing policy configurations.
* refactor(learner): Remove normalization from cached image features retrieval
- Simplified the retrieval of observation features by removing the normalization step from the `get_cached_image_features` method calls.
- This change enhances clarity and aligns with the recent updates to policy processors.
* refactor(policies): Remove unnormalization step from action predictions
- Eliminated the unnormalization of actions in both `TDMPCPolicy` and `VQBeTPolicy` classes to streamline action prediction.
- This change improves code clarity and aligns with recent updates to policy processors.
* feat(train): Integrate preprocessor into training pipeline
* refactor(train): Update preprocessor initialization to include dataset statistics
* refactor(policies): Enhance processor creation and add NaN detection hook
* feat(record): Integrate RobotProcessor into recording loop and update policy handling
- Added support for RobotProcessor in the record_loop function to enhance data processing capabilities.
- Updated the logic to reset both policy and processor when provided, ensuring proper state management.
- Modified action prediction to utilize the processor, improving the overall functionality of the recording process.
- Adjusted the save_checkpoint function to include preprocessor state saving, enhancing checkpointing capabilities.
* feat(migration): Add script for migrating policy models with normalization layers
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(migrate): Enhance migration script to create preprocessor and postprocessor for policy models
- Updated the migration script to generate both a preprocessor and a postprocessor, improving the handling of normalization for training and inference.
- Added functionality to convert features to PolicyFeature objects, ensuring compatibility with the new processor architecture.
- Refined the extraction and removal of normalization statistics and layers, streamlining the migration process.
- Improved error handling for missing mandatory configuration fields during model instantiation.
* feat(migrate): Add model card generation and saving to migration script
- Implemented functionality to generate and save a model card for the migrated model, including metadata such as dataset repository ID, license, and tags.
- Enhanced the script to push the model card to the hub if requested, improving model documentation and accessibility.
- Refactored the saving process to ensure the model card is saved locally and uploaded correctly when pushing to the hub.
* feat(processor): Introduce ToBatchProcessor for handling observation batching
- Added ToBatchProcessor to ensure observations have proper batch dimensions for model processing.
- Implemented functionality to add batch dimensions to state and image observations as needed.
- Created comprehensive unit tests to validate the processor's behavior with various tensor dimensions and types.
- Ensured compatibility with existing transition keys and maintained the integrity of non-observation data.
* feat(processors): Add ToBatchProcessor to multiple policy processors
- Integrated ToBatchProcessor into various policy processors to handle observation batching.
- Updated make functions for act, diffusion, pi0, pi0fast, sac, smolvla, tdmpc, and vqbet processors to include the new batching functionality.
- Ensured consistency across all processor implementations for improved data handling.
* refactor(factory): Remove unused imports and NaN detection hook from processor creation
* feat(batch_processor): Enhance ToBatchProcessor to handle action batching
- Updated ToBatchProcessor to add batch dimensions to actions in addition to observations.
- Implemented separate methods for processing observations and actions, improving code readability.
- Added comprehensive unit tests to validate action batching functionality across various tensor dimensions and types.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(factory): Enhance make_processor to support preprocessor and postprocessor configuration
- Introduced ProcessorConfigKwargs TypedDict for better type safety in processor configuration.
- Updated make_processor to accept preprocessor and postprocessor configuration filenames, improving flexibility in processor instantiation.
- Refactored the loading of pretrained processors to utilize the new configuration options.
* refactor(factory): Clean up imports in factory.py
- Removed unused import of IdentityProcessor to streamline the code.
* feat(migrate): Extend load_model_from_hub to include train configuration
- Updated load_model_from_hub to return the train configuration alongside the model state_dict and config.
- Modified main function to handle the additional train configuration when loading models from both the hub and local paths.
- Adjusted dataset_repo_id extraction to utilize the train configuration for improved accuracy.
* refactor(record): Rename processor parameters and update processing logic
- Renamed `processor` to `preprocessor` and added `postprocessor` parameter for clarity.
- Updated the `record_loop` and `predict_action` functions to utilize the new preprocessor and postprocessor, enhancing the processing flow.
- Ensured compatibility with existing functionality while improving code readability.
* feat(batch_processor): Add task field processing to ToBatchProcessor
- Enhanced ToBatchProcessor to wrap string tasks in a list, adding batch dimensions for compatibility with model inference.
- Implemented a new method for processing complementary data, ensuring that task values are correctly handled as either strings or lists of strings.
- Added comprehensive unit tests to validate task processing, including edge cases and in-place mutation of complementary data.
* feat(normalization): Implement IDENTITY mode for normalization and unnormalization
- Enhanced NormalizerProcessor and UnnormalizerProcessor to support IDENTITY mode, allowing features to bypass normalization when specified.
- Updated processing logic to check normalization modes and handle missing statistics gracefully.
- Added comprehensive unit tests to validate IDENTITY mode functionality for both observations and actions, ensuring correct behavior across various scenarios.
- Improved error handling for unsupported normalization modes.
* fix(rebase): remove residual normalization layer:
* refactor(diffusion): remove normalization layer from input processing
* refactor(normalization): Remove unused state dict transformation methods and streamline imports
- Eliminated the _transform_state_dict_keys and _load_as_safetensor methods from PI0Policy, simplifying the model loading process.
- Cleaned up imports in modeling_pi0.py by removing log_model_loading_keys and init_logging.
- Updated TDMPCPolicy and VQBeTPolicy to handle action removal from batches during offline evaluation.
- Introduced hotswap_stats function in normalize_processor.py to update normalization statistics dynamically, with corresponding tests to ensure functionality.
* refactor(normalization): Clean up imports in normalize_processor.py
* feat(batch_processor): Add feature_contract method to ToBatchProcessor
- Introduced feature_contract method that returns features without modification, maintaining the no-op behavior of the processor.
- This addition enhances the flexibility of the ToBatchProcessor for future feature processing needs.
* fix(dependencies): Update transformers dependency constraint to allow only versions up to 4.52.0
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feature(pipeline): port tokenizer pipeline for VLA (#1645)
* feat(tokenizer): Introduce TokenizerProcessor for text tokenization
- Added TokenizerProcessor class to handle tokenization of task strings using Hugging Face's AutoTokenizer.
- Supports both string and list inputs, with customizable parameters for task key, output key, and tokenization settings.
- Implemented comprehensive unit tests to validate functionality, including handling of various input scenarios and integration with RobotProcessor.
- Updated types.py to include LANGUAGE feature type and modified __init__.py to register the new processor.
* feat(language): Enhance language processing in TokenizerProcessor
- Added OBS_LANGUAGE constant to define the observation language key.
- Updated TokenizerProcessor to store tokenized task data in the observation dictionary, ensuring compatibility with the new language feature.
- Introduced Pi0NewLineProcessor to append newlines to tasks for proper tokenization.
- Modified tests to validate the integration of language tokens and attention masks in the observation structure.
* feat(tokenizer): Add padding configuration to TokenizerProcessor
- Introduced `padding_side` parameter to the TokenizerProcessor for customizable padding direction.
- Updated the `make_pi0_processor` function to include the new padding configuration.
- Enhanced unit tests to validate the functionality of the `padding_side` parameter in various scenarios.
* feat(processor): Add state management methods to Pi0NewLineProcessor
* feat(normalization): Track normalization and unnormalization info in complementary data
- Updated NormalizerProcessor and UnnormalizerProcessor to accept additional parameters for tracking normalization modes.
- Enhanced the __call__ methods to store normalization and unnormalization information in the complementary data of transitions.
- Added unit tests to verify the correct tracking of normalization info, including scenarios with missing stats and selective normalization keys.
* feat(factory): Add preprocessor and postprocessor overrides to ProcessorConfigKwargs
- Updated ProcessorConfigKwargs to include optional overrides for preprocessor and postprocessor configurations.
- Enhanced the make_processor function to utilize the new overrides, allowing for more flexible processor initialization.
* feat(processors): Integrate RenameProcessor into various processor configurations
- Added RenameProcessor to the input steps of multiple processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Consolidated normalization features from input and output into a single NormalizerProcessor for improved efficiency.
- Updated the input steps to ensure compatibility with the new RenameProcessor integration.
* feat(smolvla): Refactor language processing and introduce new line processor (#1658)
- Removed the prepare_language method and directly accessed language tokens and masks from the batch using the OBS_LANGUAGE constant.
- Added SmolVLANewLineProcessor to ensure tasks end with a newline, enhancing tokenization compatibility.
- Updated the make_smolvla_processor function to include the new line processor and tokenizer processor for improved input handling.
* feture(policies): add device processor (#1659)
* feat(processors): Integrate DeviceProcessor into multiple processor configurations
- Added DeviceProcessor to the input and output steps of various processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_pi0fast_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Enhanced the DeviceProcessor class with state management methods and ensured compatibility with existing processor pipelines.
- Introduced unit tests for DeviceProcessor to validate functionality across different scenarios, including CPU and CUDA operations.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Remove to() method for device management
- Eliminated the to() method from RobotProcessor, which was responsible for moving tensor states to specified devices.
- Removed associated unit tests that validated the functionality of the to() method across various scenarios.
- Streamlined the pipeline code by focusing on other device management strategies.
* feat(processor): Enhance DeviceProcessor with float dtype conversion
- Added support for optional float dtype conversion in DeviceProcessor, allowing tensors to be converted to specified floating-point types while preserving non-float types.
- Implemented validation for float dtype input and updated the processor's configuration methods to include float dtype.
- Refactored tensor processing logic to streamline device movement and dtype conversion.
- Introduced comprehensive unit tests to validate the new float dtype functionality across various scenarios.
* feat(policies): Add new line processors and update module exports
* feat(processor): Enhance batch and device processors to handle index and task_index fields
- Added logic to ToBatchProcessor for unsqueezing 0D tensors for index and task_index fields, ensuring they are processed as 1D tensors.
- Updated DeviceProcessor to process index and task_index fields in complementary data, preserving their tensor types and ensuring non-tensor fields remain unchanged.
- Enhanced unit tests to validate the correct handling of index and task_index fields across various scenarios, including device compatibility and dtype preservation.
* refactor(processors): Standardize processor naming conventions
- Updated processor names across various files to use a consistent "robot_preprocessor" and "robot_postprocessor" format.
- Modified the make_processor functions in factory, act, diffusion, pi0, pi0fast, sac, smolvla, tdmpc, and vqbet to reflect the new naming scheme.
- Enhanced the pipeline configuration to align with the updated processor names, improving clarity and maintainability.
* refactor(factory): Update processor configuration and type hints
- Changed return type of get_policy_class to type[PreTrainedPolicy] for improved type safety.
- Enhanced make_processor function to utilize dataset_stats in processor creation for better flexibility.
- Updated ProcessorConfigKwargs to include dataset_stats, allowing for more comprehensive processor configurations.
- Streamlined processor initialization by removing unnecessary kwargs and ensuring clarity in processor type handling.
* Fix eval and android gripper
* add some tests
* refactor(factory, pi0fast): Update processor function names and parameters
- Renamed make_pi0_processor to make_pi0fast_processor for clarity and consistency.
- Updated parameter names in the factory's make_processor function to use pretrained_model_name_or_path instead of source, enhancing readability and alignment with naming conventions.
* fix(train.py) push postprocessor with preprocessor
- Add preprocesser policy overrides for device and rename_map
- Add rename_map to DatasetRecordConfig (record.py)
* Cleanup pr
* fix more git diff pr issues
* add path as type in save_pretrained
* small nit
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* rename test file
* fix: make dataset_features/feature_contract is optional
* fix tests
* Encorperate pr feedback
* clean up record.py
* add ascii art, fix normal record
* remove merge issues
* fix merge
* remove features
* Add feedback PR
* fix last 4 tests
* remove features check
* rename to transform_features
* add transform_features
* fix lekiwi eval and update eval api example
---------
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
Signed-off-by: Pepijn <138571049+pkooij@users.noreply.github.com>
Co-authored-by: Adil Zouitine <adilzouitinegm@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Simon Alibert <75076266+aliberts@users.noreply.github.com>
Co-authored-by: Michel Aractingi <michel.aractingi@huggingface.co>
2025-08-07 16:13:34 +02:00
|
|
|
|
* ``transform_features(features: dict[str, PolicyFeature]) -> dict[str, PolicyFeature]``
|
|
|
|
|
|
If present, this method will be called to aggregate the dataset features of all steps.
|
2025-07-02 15:31:15 +00:00
|
|
|
|
|
2025-07-02 17:29:58 +02:00
|
|
|
|
Example separation:
|
|
|
|
|
|
- get_config(): {"name": "my_step", "learning_rate": 0.01, "window_size": 10}
|
|
|
|
|
|
- state_dict(): {"weights": torch.tensor(...), "running_mean": torch.tensor(...)}
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
2025-08-31 20:38:52 +02:00
|
|
|
|
_current_transition: EnvTransition | None = None
|
2025-07-02 17:29:58 +02:00
|
|
|
|
|
2025-08-31 20:38:52 +02:00
|
|
|
|
@property
|
|
|
|
|
|
def transition(self) -> EnvTransition:
|
|
|
|
|
|
"""The current transition being processed by this step."""
|
|
|
|
|
|
if self._current_transition is None:
|
|
|
|
|
|
raise ValueError("Transition is not set. Make sure to call the step with a transition first.")
|
|
|
|
|
|
return self._current_transition
|
2025-07-02 17:29:58 +02:00
|
|
|
|
|
2025-08-31 20:38:52 +02:00
|
|
|
|
@abstractmethod
|
|
|
|
|
|
def __call__(self, transition: EnvTransition) -> EnvTransition:
|
|
|
|
|
|
return transition
|
|
|
|
|
|
|
|
|
|
|
|
def get_config(self) -> dict[str, Any]:
|
|
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
|
|
def state_dict(self) -> dict[str, torch.Tensor]:
|
|
|
|
|
|
return {}
|
2025-07-02 17:29:58 +02:00
|
|
|
|
|
2025-08-31 20:38:52 +02:00
|
|
|
|
def load_state_dict(self, state: dict[str, torch.Tensor]) -> None:
|
|
|
|
|
|
return None
|
2025-07-02 17:29:58 +02:00
|
|
|
|
|
2025-08-31 20:38:52 +02:00
|
|
|
|
def reset(self) -> None:
|
|
|
|
|
|
return None
|
2025-07-02 17:29:58 +02:00
|
|
|
|
|
2025-09-02 17:15:01 +02:00
|
|
|
|
@abstractmethod
|
2025-08-31 20:38:52 +02:00
|
|
|
|
def transform_features(self, features: dict[str, PolicyFeature]) -> dict[str, PolicyFeature]:
|
|
|
|
|
|
return features
|
2025-07-31 16:29:48 +02:00
|
|
|
|
|
2025-07-02 17:29:58 +02:00
|
|
|
|
|
2025-09-02 12:57:14 +02:00
|
|
|
|
class ProcessorKwargs(TypedDict, total=False):
|
2025-09-03 17:13:16 +02:00
|
|
|
|
"""Keyword arguments for DataProcessorPipeline constructor."""
|
2025-09-02 12:57:14 +02:00
|
|
|
|
|
|
|
|
|
|
to_transition: Callable[[dict[str, Any]], EnvTransition] | None
|
|
|
|
|
|
to_output: Callable[[EnvTransition], Any] | None
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-07-02 17:29:58 +02:00
|
|
|
|
@dataclass
|
2025-09-03 17:13:16 +02:00
|
|
|
|
class DataProcessorPipeline(ModelHubMixin, Generic[TOutput]):
|
2025-07-02 17:29:58 +02:00
|
|
|
|
"""
|
2025-07-03 14:11:28 +02:00
|
|
|
|
Composable, debuggable post-processing processor for robot transitions.
|
2025-07-06 22:03:37 +02:00
|
|
|
|
|
|
|
|
|
|
The class orchestrates an ordered collection of small, functional transforms—steps—executed
|
2025-08-06 14:00:13 +02:00
|
|
|
|
left-to-right on each incoming `EnvTransition`. It can process both `EnvTransition` dicts
|
2025-07-06 22:03:37 +02:00
|
|
|
|
and batch dictionaries, automatically converting between formats as needed.
|
|
|
|
|
|
|
2025-09-02 12:57:14 +02:00
|
|
|
|
The processor is generic over its output type TOutput, which provides better type safety
|
|
|
|
|
|
and clarity about what the processor returns.
|
|
|
|
|
|
|
2025-07-06 22:03:37 +02:00
|
|
|
|
Args:
|
|
|
|
|
|
steps: Ordered list of processing steps executed on every call. Defaults to empty list.
|
|
|
|
|
|
name: Human-readable identifier that is persisted inside the JSON config.
|
2025-09-03 17:13:16 +02:00
|
|
|
|
Defaults to "DataProcessorPipeline".
|
2025-08-06 14:00:13 +02:00
|
|
|
|
to_transition: Function to convert batch dict to EnvTransition dict.
|
2025-07-06 22:03:37 +02:00
|
|
|
|
Defaults to _default_batch_to_transition.
|
2025-09-02 12:57:14 +02:00
|
|
|
|
to_output: Function to convert EnvTransition dict to the desired output format of type TOutput.
|
|
|
|
|
|
Defaults to _default_transition_to_batch (returns batch dict).
|
|
|
|
|
|
Use identity function (lambda x: x) for EnvTransition output.
|
2025-07-06 22:03:37 +02:00
|
|
|
|
before_step_hooks: List of hooks called before each step. Each hook receives the step
|
|
|
|
|
|
index and transition, and can optionally return a modified transition.
|
|
|
|
|
|
after_step_hooks: List of hooks called after each step. Each hook receives the step
|
|
|
|
|
|
index and transition, and can optionally return a modified transition.
|
2025-07-21 18:56:01 +02:00
|
|
|
|
|
2025-09-02 12:57:14 +02:00
|
|
|
|
Type Safety Examples:
|
|
|
|
|
|
```python
|
|
|
|
|
|
# Default behavior - returns batch dict
|
2025-09-03 17:13:16 +02:00
|
|
|
|
processor: DataProcessorPipeline[dict[str, Any]] = DataProcessorPipeline(
|
|
|
|
|
|
steps=[some_step1, some_step2]
|
|
|
|
|
|
)
|
2025-09-02 12:57:14 +02:00
|
|
|
|
result: dict[str, Any] = processor(batch_data) # Type checker knows this is a dict
|
|
|
|
|
|
|
|
|
|
|
|
# For EnvTransition output, explicitly specify identity function
|
2025-09-03 17:13:16 +02:00
|
|
|
|
transition_processor: DataProcessorPipeline[EnvTransition] = DataProcessorPipeline(
|
2025-09-02 12:57:14 +02:00
|
|
|
|
steps=[some_step1, some_step2],
|
|
|
|
|
|
to_output=lambda x: x, # Identity function
|
|
|
|
|
|
)
|
|
|
|
|
|
result: EnvTransition = transition_processor(batch_data) # Type checker knows this is EnvTransition
|
|
|
|
|
|
|
|
|
|
|
|
# For custom output types
|
2025-09-03 17:13:16 +02:00
|
|
|
|
processor: DataProcessorPipeline[str] = DataProcessorPipeline(
|
2025-09-02 12:57:14 +02:00
|
|
|
|
steps=[custom_step], to_output=lambda t: f"Processed {len(t)} keys"
|
|
|
|
|
|
)
|
|
|
|
|
|
result: str = processor(batch_data) # Type checker knows this is str
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2025-07-21 18:56:01 +02:00
|
|
|
|
Hook Semantics:
|
|
|
|
|
|
- Hooks are executed sequentially in the order they were registered. There is no way to
|
|
|
|
|
|
reorder hooks after registration without creating a new pipeline.
|
2025-07-22 10:41:22 +02:00
|
|
|
|
- Hooks are for observation/monitoring only and DO NOT modify transitions. They are called
|
|
|
|
|
|
with the step index and current transition for logging, debugging, or monitoring purposes.
|
2025-07-21 18:56:01 +02:00
|
|
|
|
- All hooks for a given type (before/after) are executed for every step, or none at all if
|
|
|
|
|
|
an error occurs. There is no partial execution of hooks.
|
|
|
|
|
|
- Hooks should generally be stateless to maintain predictable behavior. If you need stateful
|
|
|
|
|
|
processing, consider implementing a proper ProcessorStep instead.
|
|
|
|
|
|
- To remove hooks, use the unregister methods. To remove steps, you must create a new pipeline.
|
2025-08-02 14:51:52 +02:00
|
|
|
|
- Hooks ALWAYS receive transitions in EnvTransition format, regardless of the input format
|
|
|
|
|
|
passed to __call__. This ensures consistent hook behavior whether processing batch dicts
|
|
|
|
|
|
or EnvTransition objects.
|
2025-07-02 17:29:58 +02:00
|
|
|
|
"""
|
2025-07-02 15:31:15 +00:00
|
|
|
|
|
2025-07-03 14:11:28 +02:00
|
|
|
|
steps: Sequence[ProcessorStep] = field(default_factory=list)
|
2025-09-03 17:13:16 +02:00
|
|
|
|
name: str = "DataProcessorPipeline"
|
2025-07-02 17:29:58 +02:00
|
|
|
|
|
2025-09-02 15:33:38 +02:00
|
|
|
|
to_transition: Callable[[dict[str, Any]], EnvTransition] = field(default=batch_to_transition, repr=False)
|
2025-09-02 12:57:14 +02:00
|
|
|
|
to_output: Callable[[EnvTransition], TOutput] = field(
|
|
|
|
|
|
# Cast is necessary here: Working around Python type-checker limitation.
|
|
|
|
|
|
# _default_transition_to_batch returns dict[str, Any], but we need it to be TOutput
|
|
|
|
|
|
# for the generic to work. When no explicit type is given, TOutput defaults to dict[str, Any],
|
|
|
|
|
|
# making this cast safe.
|
2025-09-02 15:33:38 +02:00
|
|
|
|
default_factory=lambda: cast(Callable[[EnvTransition], TOutput], transition_to_batch),
|
2025-09-02 12:57:14 +02:00
|
|
|
|
repr=False,
|
2025-07-06 21:29:51 +02:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-07-22 10:41:22 +02:00
|
|
|
|
# Processor-level hooks for observation/monitoring
|
|
|
|
|
|
# Hooks do not modify transitions - they are called for logging, debugging, or monitoring purposes
|
|
|
|
|
|
before_step_hooks: list[Callable[[int, EnvTransition], None]] = field(default_factory=list, repr=False)
|
|
|
|
|
|
after_step_hooks: list[Callable[[int, EnvTransition], None]] = field(default_factory=list, repr=False)
|
2025-07-02 17:29:58 +02:00
|
|
|
|
|
2025-09-02 12:57:14 +02:00
|
|
|
|
def __call__(self, data: dict[str, Any]) -> TOutput:
|
2025-07-06 22:03:37 +02:00
|
|
|
|
"""Process data through all steps.
|
|
|
|
|
|
|
2025-09-02 12:57:14 +02:00
|
|
|
|
The method accepts a batch dictionary (like the ones returned by ReplayBuffer or
|
|
|
|
|
|
LeRobotDataset). It is first converted to EnvTransition format using to_transition,
|
|
|
|
|
|
then processed through all steps, and finally converted to the output format using to_output.
|
2025-07-06 22:03:37 +02:00
|
|
|
|
|
|
|
|
|
|
Args:
|
2025-09-02 12:57:14 +02:00
|
|
|
|
data: A batch dictionary to process.
|
2025-07-06 22:03:37 +02:00
|
|
|
|
|
|
|
|
|
|
Returns:
|
2025-09-02 12:57:14 +02:00
|
|
|
|
The processed data in the format specified by to_output.
|
2025-07-06 21:29:51 +02:00
|
|
|
|
"""
|
2025-09-02 12:57:14 +02:00
|
|
|
|
# Always convert input through to_transition
|
|
|
|
|
|
transition = self.to_transition(data)
|
2025-08-02 14:51:52 +02:00
|
|
|
|
|
2025-09-03 12:28:40 +02:00
|
|
|
|
transformed_transition = self._forward(transition)
|
|
|
|
|
|
|
|
|
|
|
|
# Always use to_output for consistent typing
|
|
|
|
|
|
return self.to_output(transformed_transition)
|
|
|
|
|
|
|
|
|
|
|
|
def _forward(self, transition: EnvTransition) -> EnvTransition:
|
2025-09-02 12:57:14 +02:00
|
|
|
|
# Process through all steps
|
|
|
|
|
|
for idx, processor_step in enumerate(self.steps):
|
|
|
|
|
|
# Apply before hooks
|
2025-07-22 10:41:22 +02:00
|
|
|
|
for hook in self.before_step_hooks:
|
2025-09-02 12:57:14 +02:00
|
|
|
|
hook(idx, transition)
|
2025-07-22 10:41:22 +02:00
|
|
|
|
|
2025-09-02 12:57:14 +02:00
|
|
|
|
# Execute step
|
|
|
|
|
|
transition = processor_step(transition)
|
2025-07-06 21:29:51 +02:00
|
|
|
|
|
2025-09-02 12:57:14 +02:00
|
|
|
|
# Apply after hooks
|
2025-08-02 14:51:52 +02:00
|
|
|
|
for hook in self.after_step_hooks:
|
2025-09-02 12:57:14 +02:00
|
|
|
|
hook(idx, transition)
|
2025-09-03 12:28:40 +02:00
|
|
|
|
return transition
|
2025-07-22 10:41:22 +02:00
|
|
|
|
|
2025-09-02 12:57:14 +02:00
|
|
|
|
def step_through(self, data: dict[str, Any]) -> Iterable[EnvTransition]:
|
2025-07-08 13:14:58 +02:00
|
|
|
|
"""Yield the intermediate results after each processor step.
|
|
|
|
|
|
|
2025-07-22 10:41:22 +02:00
|
|
|
|
This is a low-level method that does NOT apply hooks. It simply executes each step
|
|
|
|
|
|
and yields the intermediate results. This allows users to debug the pipeline or
|
|
|
|
|
|
apply custom logic between steps if needed.
|
|
|
|
|
|
|
2025-09-02 12:57:14 +02:00
|
|
|
|
Note: This method always yields EnvTransition objects regardless of output format.
|
|
|
|
|
|
If you need the results in the output format, you'll need to convert them
|
2025-08-02 14:51:52 +02:00
|
|
|
|
using `to_output()`.
|
2025-07-08 13:14:58 +02:00
|
|
|
|
|
|
|
|
|
|
Args:
|
2025-09-02 12:57:14 +02:00
|
|
|
|
data: A batch dictionary to process.
|
2025-07-08 13:14:58 +02:00
|
|
|
|
|
|
|
|
|
|
Yields:
|
2025-08-02 14:51:52 +02:00
|
|
|
|
The intermediate EnvTransition results after each step.
|
2025-07-08 13:14:58 +02:00
|
|
|
|
"""
|
2025-09-02 12:57:14 +02:00
|
|
|
|
# Always convert input through to_transition
|
|
|
|
|
|
transition = self.to_transition(data)
|
2025-07-08 13:14:58 +02:00
|
|
|
|
|
|
|
|
|
|
# Yield initial state
|
2025-08-02 14:51:52 +02:00
|
|
|
|
yield transition
|
2025-07-08 13:14:58 +02:00
|
|
|
|
|
2025-07-22 10:41:22 +02:00
|
|
|
|
# Process each step WITHOUT hooks (low-level method)
|
|
|
|
|
|
for processor_step in self.steps:
|
2025-07-03 14:11:28 +02:00
|
|
|
|
transition = processor_step(transition)
|
2025-08-02 14:51:52 +02:00
|
|
|
|
yield transition
|
2025-07-02 17:29:58 +02:00
|
|
|
|
|
2025-08-05 17:44:21 +02:00
|
|
|
|
def _save_pretrained(self, save_directory: Path, **kwargs):
|
2025-07-02 17:29:58 +02:00
|
|
|
|
"""Internal save method for ModelHubMixin compatibility."""
|
2025-07-22 14:35:34 +02:00
|
|
|
|
# Extract config_filename from kwargs if provided
|
|
|
|
|
|
config_filename = kwargs.pop("config_filename", None)
|
2025-08-05 17:44:21 +02:00
|
|
|
|
self.save_pretrained(save_directory, config_filename=config_filename)
|
2025-07-02 15:31:15 +00:00
|
|
|
|
|
2025-08-05 17:44:21 +02:00
|
|
|
|
def save_pretrained(self, save_directory: str | Path, config_filename: str | None = None, **kwargs):
|
|
|
|
|
|
"""Serialize the processor definition and parameters to *save_directory*.
|
2025-07-22 14:35:34 +02:00
|
|
|
|
|
|
|
|
|
|
Args:
|
2025-08-05 17:44:21 +02:00
|
|
|
|
save_directory: Directory where the processor will be saved.
|
2025-07-22 14:35:34 +02:00
|
|
|
|
config_filename: Optional custom config filename. If not provided, defaults to
|
|
|
|
|
|
"{self.name}.json" where self.name is sanitized for filesystem compatibility.
|
|
|
|
|
|
"""
|
2025-08-05 17:44:21 +02:00
|
|
|
|
os.makedirs(str(save_directory), exist_ok=True)
|
2025-07-02 17:29:58 +02:00
|
|
|
|
|
2025-07-23 09:41:03 +02:00
|
|
|
|
# Sanitize processor name for use in filenames
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
2025-07-23 11:43:02 +02:00
|
|
|
|
# The huggingface hub does not allow special characters in the repo name, so we sanitize the name
|
2025-07-23 09:41:03 +02:00
|
|
|
|
sanitized_name = re.sub(r"[^a-zA-Z0-9_]", "_", self.name.lower())
|
2025-07-22 14:35:34 +02:00
|
|
|
|
|
2025-07-23 09:41:03 +02:00
|
|
|
|
# Use sanitized name for config if not provided
|
|
|
|
|
|
if config_filename is None:
|
2025-07-22 14:35:34 +02:00
|
|
|
|
config_filename = f"{sanitized_name}.json"
|
|
|
|
|
|
|
2025-07-02 15:31:15 +00:00
|
|
|
|
config: dict[str, Any] = {
|
2025-07-02 17:29:58 +02:00
|
|
|
|
"name": self.name,
|
|
|
|
|
|
"steps": [],
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-03 14:11:28 +02:00
|
|
|
|
for step_index, processor_step in enumerate(self.steps):
|
|
|
|
|
|
# Check if step was registered
|
|
|
|
|
|
registry_name = getattr(processor_step.__class__, "_registry_name", None)
|
|
|
|
|
|
|
2025-08-05 17:44:21 +02:00
|
|
|
|
step_entry: dict[str, Any] = {}
|
2025-07-03 14:11:28 +02:00
|
|
|
|
if registry_name:
|
|
|
|
|
|
# Use registry name for registered steps
|
2025-08-05 17:44:21 +02:00
|
|
|
|
step_entry["registry_name"] = registry_name
|
2025-07-03 14:11:28 +02:00
|
|
|
|
else:
|
|
|
|
|
|
# Fall back to full module path for unregistered steps
|
2025-08-05 17:44:21 +02:00
|
|
|
|
step_entry["class"] = (
|
|
|
|
|
|
f"{processor_step.__class__.__module__}.{processor_step.__class__.__name__}"
|
|
|
|
|
|
)
|
2025-07-03 14:11:28 +02:00
|
|
|
|
|
|
|
|
|
|
if hasattr(processor_step, "get_config"):
|
|
|
|
|
|
step_entry["config"] = processor_step.get_config()
|
|
|
|
|
|
|
|
|
|
|
|
if hasattr(processor_step, "state_dict"):
|
|
|
|
|
|
state = processor_step.state_dict()
|
2025-07-02 17:29:58 +02:00
|
|
|
|
if state:
|
2025-07-03 14:11:28 +02:00
|
|
|
|
# Clone tensors to avoid shared memory issues
|
|
|
|
|
|
# This ensures each tensor has its own memory allocation
|
|
|
|
|
|
# The reason is to avoid the following error:
|
|
|
|
|
|
# RuntimeError: Some tensors share memory, this will lead to duplicate memory on disk
|
|
|
|
|
|
# and potential differences when loading them again
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
# Since the state_dict of processor will be light, we can just clone the tensors
|
|
|
|
|
|
# and save them to the disk.
|
|
|
|
|
|
cloned_state = {}
|
|
|
|
|
|
for key, tensor in state.items():
|
|
|
|
|
|
cloned_state[key] = tensor.clone()
|
|
|
|
|
|
|
2025-07-23 09:41:03 +02:00
|
|
|
|
# Include pipeline name and step index to ensure unique filenames
|
|
|
|
|
|
# This prevents conflicts when multiple processors are saved in the same directory
|
2025-07-22 11:28:30 +02:00
|
|
|
|
if registry_name:
|
2025-07-23 09:41:03 +02:00
|
|
|
|
state_filename = f"{sanitized_name}_step_{step_index}_{registry_name}.safetensors"
|
2025-07-22 11:28:30 +02:00
|
|
|
|
else:
|
2025-07-23 09:41:03 +02:00
|
|
|
|
state_filename = f"{sanitized_name}_step_{step_index}.safetensors"
|
2025-07-22 11:28:30 +02:00
|
|
|
|
|
2025-08-05 17:44:21 +02:00
|
|
|
|
save_file(cloned_state, os.path.join(str(save_directory), state_filename))
|
2025-07-02 17:29:58 +02:00
|
|
|
|
step_entry["state_file"] = state_filename
|
|
|
|
|
|
|
|
|
|
|
|
config["steps"].append(step_entry)
|
|
|
|
|
|
|
2025-08-05 17:44:21 +02:00
|
|
|
|
with open(os.path.join(str(save_directory), config_filename), "w") as file_pointer:
|
2025-07-02 17:29:58 +02:00
|
|
|
|
json.dump(config, file_pointer, indent=2)
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
2025-07-22 14:35:34 +02:00
|
|
|
|
def from_pretrained(
|
2025-08-05 17:44:21 +02:00
|
|
|
|
cls,
|
|
|
|
|
|
pretrained_model_name_or_path: str | Path,
|
|
|
|
|
|
*,
|
|
|
|
|
|
force_download: bool = False,
|
|
|
|
|
|
resume_download: bool | None = None,
|
|
|
|
|
|
proxies: dict[str, str] | None = None,
|
|
|
|
|
|
token: str | bool | None = None,
|
|
|
|
|
|
cache_dir: str | Path | None = None,
|
|
|
|
|
|
local_files_only: bool = False,
|
|
|
|
|
|
revision: str | None = None,
|
|
|
|
|
|
config_filename: str | None = None,
|
|
|
|
|
|
overrides: dict[str, Any] | None = None,
|
2025-09-02 12:57:14 +02:00
|
|
|
|
to_transition: Callable[[dict[str, Any]], EnvTransition] | None = None,
|
|
|
|
|
|
to_output: Callable[[EnvTransition], TOutput] | None = None,
|
2025-08-05 17:44:21 +02:00
|
|
|
|
**kwargs,
|
2025-09-03 17:13:16 +02:00
|
|
|
|
) -> DataProcessorPipeline[TOutput]:
|
2025-07-07 12:01:34 +02:00
|
|
|
|
"""Load a serialized processor from source (local path or Hugging Face Hub identifier).
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
2025-08-05 17:44:21 +02:00
|
|
|
|
pretrained_model_name_or_path: Local path to a saved processor directory or Hugging Face Hub identifier
|
2025-07-07 12:01:34 +02:00
|
|
|
|
(e.g., "username/processor-name").
|
2025-07-22 14:35:34 +02:00
|
|
|
|
config_filename: Optional specific config filename to load. If not provided, will:
|
|
|
|
|
|
- For local paths: look for any .json file in the directory (error if multiple found)
|
|
|
|
|
|
- For HF Hub: try common names ("processor.json", "preprocessor.json", "postprocessor.json")
|
2025-07-07 12:01:34 +02:00
|
|
|
|
overrides: Optional dictionary mapping step names to configuration overrides.
|
|
|
|
|
|
Keys must match exact step class names (for unregistered steps) or registry names
|
|
|
|
|
|
(for registered steps). Values are dictionaries containing parameter overrides
|
|
|
|
|
|
that will be merged with the saved configuration. This is useful for providing
|
|
|
|
|
|
non-serializable objects like environment instances.
|
2025-09-02 12:57:14 +02:00
|
|
|
|
to_transition: Function to convert batch dict to EnvTransition dict.
|
|
|
|
|
|
Defaults to _default_batch_to_transition.
|
|
|
|
|
|
to_output: Function to convert EnvTransition dict to the desired output format of type T.
|
|
|
|
|
|
Defaults to _default_transition_to_batch (returns batch dict).
|
|
|
|
|
|
Use identity function (lambda x: x) for EnvTransition output.
|
2025-07-07 12:01:34 +02:00
|
|
|
|
|
|
|
|
|
|
Returns:
|
2025-09-03 17:13:16 +02:00
|
|
|
|
A DataProcessorPipeline[TOutput] instance loaded from the saved configuration.
|
2025-07-07 12:01:34 +02:00
|
|
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
|
|
ImportError: If a processor step class cannot be loaded or imported.
|
|
|
|
|
|
ValueError: If a step cannot be instantiated with the provided configuration.
|
|
|
|
|
|
KeyError: If an override key doesn't match any step in the saved configuration.
|
|
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
Basic loading:
|
|
|
|
|
|
```python
|
2025-09-03 17:13:16 +02:00
|
|
|
|
processor = DataProcessorPipeline.from_pretrained("path/to/processor")
|
2025-07-07 12:01:34 +02:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-07-22 14:35:34 +02:00
|
|
|
|
Loading specific config file:
|
|
|
|
|
|
```python
|
2025-09-03 17:13:16 +02:00
|
|
|
|
processor = DataProcessorPipeline.from_pretrained(
|
2025-07-22 14:35:34 +02:00
|
|
|
|
"username/multi-processor-repo", config_filename="preprocessor.json"
|
|
|
|
|
|
)
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2025-07-07 12:01:34 +02:00
|
|
|
|
Loading with overrides for non-serializable objects:
|
|
|
|
|
|
```python
|
|
|
|
|
|
import gym
|
2025-07-21 08:06:31 +00:00
|
|
|
|
|
2025-07-07 12:01:34 +02:00
|
|
|
|
env = gym.make("CartPole-v1")
|
2025-09-03 17:13:16 +02:00
|
|
|
|
processor = DataProcessorPipeline.from_pretrained(
|
2025-07-21 08:06:31 +00:00
|
|
|
|
"username/cartpole-processor", overrides={"ActionRepeatStep": {"env": env}}
|
2025-07-07 12:01:34 +02:00
|
|
|
|
)
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
Multiple overrides:
|
|
|
|
|
|
```python
|
2025-09-03 17:13:16 +02:00
|
|
|
|
processor = DataProcessorPipeline.from_pretrained(
|
2025-07-07 12:01:34 +02:00
|
|
|
|
"path/to/processor",
|
|
|
|
|
|
overrides={
|
|
|
|
|
|
"CustomStep": {"param1": "new_value"},
|
2025-07-21 08:06:31 +00:00
|
|
|
|
"device_processor": {"device": "cuda:1"}, # For registered steps
|
|
|
|
|
|
},
|
2025-07-07 12:01:34 +02:00
|
|
|
|
)
|
|
|
|
|
|
```
|
|
|
|
|
|
"""
|
2025-08-05 17:44:21 +02:00
|
|
|
|
# Use the local variable name 'source' for clarity
|
|
|
|
|
|
source = str(pretrained_model_name_or_path)
|
|
|
|
|
|
|
2025-07-02 17:29:58 +02:00
|
|
|
|
if Path(source).is_dir():
|
|
|
|
|
|
# Local path - use it directly
|
|
|
|
|
|
base_path = Path(source)
|
2025-07-22 14:35:34 +02:00
|
|
|
|
|
|
|
|
|
|
if config_filename is None:
|
|
|
|
|
|
# Look for any .json file in the directory
|
|
|
|
|
|
json_files = list(base_path.glob("*.json"))
|
|
|
|
|
|
if len(json_files) == 0:
|
|
|
|
|
|
raise FileNotFoundError(f"No .json configuration files found in {source}")
|
|
|
|
|
|
elif len(json_files) > 1:
|
|
|
|
|
|
raise ValueError(
|
|
|
|
|
|
f"Multiple .json files found in {source}: {[f.name for f in json_files]}. "
|
|
|
|
|
|
f"Please specify which one to load using the config_filename parameter."
|
|
|
|
|
|
)
|
|
|
|
|
|
config_filename = json_files[0].name
|
|
|
|
|
|
|
|
|
|
|
|
with open(base_path / config_filename) as file_pointer:
|
2025-08-05 17:44:21 +02:00
|
|
|
|
loaded_config: dict[str, Any] = json.load(file_pointer)
|
2025-07-02 17:29:58 +02:00
|
|
|
|
else:
|
|
|
|
|
|
# Hugging Face Hub - download all required files
|
2025-07-22 14:35:34 +02:00
|
|
|
|
if config_filename is None:
|
|
|
|
|
|
# Try common config names
|
|
|
|
|
|
common_names = [
|
2025-08-05 14:40:19 +02:00
|
|
|
|
"robot_processor.json",
|
|
|
|
|
|
"robot_preprocessor.json",
|
|
|
|
|
|
"robot_postprocessor.json",
|
2025-07-22 14:35:34 +02:00
|
|
|
|
]
|
|
|
|
|
|
config_path = None
|
|
|
|
|
|
for name in common_names:
|
|
|
|
|
|
try:
|
2025-08-05 17:44:21 +02:00
|
|
|
|
config_path = hf_hub_download(
|
|
|
|
|
|
source,
|
|
|
|
|
|
name,
|
|
|
|
|
|
repo_type="model",
|
|
|
|
|
|
force_download=force_download,
|
|
|
|
|
|
resume_download=resume_download,
|
|
|
|
|
|
proxies=proxies,
|
|
|
|
|
|
token=token,
|
|
|
|
|
|
cache_dir=cache_dir,
|
|
|
|
|
|
local_files_only=local_files_only,
|
|
|
|
|
|
revision=revision,
|
|
|
|
|
|
)
|
2025-07-22 14:35:34 +02:00
|
|
|
|
config_filename = name
|
|
|
|
|
|
break
|
|
|
|
|
|
except (FileNotFoundError, OSError, HfHubHTTPError):
|
|
|
|
|
|
# FileNotFoundError: local file issues
|
|
|
|
|
|
# OSError: network/system errors
|
|
|
|
|
|
# HfHubHTTPError: file not found on Hub (404) or other HTTP errors
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
if config_path is None:
|
|
|
|
|
|
raise FileNotFoundError(
|
|
|
|
|
|
f"No processor configuration file found in {source}. "
|
|
|
|
|
|
f"Tried: {common_names}. Please specify the config_filename parameter."
|
|
|
|
|
|
)
|
|
|
|
|
|
else:
|
|
|
|
|
|
# Download specific config file
|
2025-08-05 17:44:21 +02:00
|
|
|
|
config_path = hf_hub_download(
|
|
|
|
|
|
source,
|
|
|
|
|
|
config_filename,
|
|
|
|
|
|
repo_type="model",
|
|
|
|
|
|
force_download=force_download,
|
|
|
|
|
|
resume_download=resume_download,
|
|
|
|
|
|
proxies=proxies,
|
|
|
|
|
|
token=token,
|
|
|
|
|
|
cache_dir=cache_dir,
|
|
|
|
|
|
local_files_only=local_files_only,
|
|
|
|
|
|
revision=revision,
|
|
|
|
|
|
)
|
2025-07-22 14:35:34 +02:00
|
|
|
|
|
2025-07-02 17:29:58 +02:00
|
|
|
|
with open(config_path) as file_pointer:
|
2025-08-05 17:44:21 +02:00
|
|
|
|
loaded_config = json.load(file_pointer)
|
2025-07-02 15:31:15 +00:00
|
|
|
|
|
2025-07-02 17:29:58 +02:00
|
|
|
|
# Store downloaded files in the same directory as the config
|
|
|
|
|
|
base_path = Path(config_path).parent
|
|
|
|
|
|
|
2025-07-07 12:01:34 +02:00
|
|
|
|
# Handle None overrides
|
|
|
|
|
|
if overrides is None:
|
|
|
|
|
|
overrides = {}
|
|
|
|
|
|
|
|
|
|
|
|
# Validate that all override keys will be matched
|
|
|
|
|
|
override_keys = set(overrides.keys())
|
|
|
|
|
|
|
2025-07-03 14:11:28 +02:00
|
|
|
|
steps: list[ProcessorStep] = []
|
2025-08-05 17:44:21 +02:00
|
|
|
|
for step_entry in loaded_config["steps"]:
|
2025-07-03 14:11:28 +02:00
|
|
|
|
# Check if step uses registry name or module path
|
|
|
|
|
|
if "registry_name" in step_entry:
|
|
|
|
|
|
# Load from registry
|
|
|
|
|
|
try:
|
|
|
|
|
|
step_class = ProcessorStepRegistry.get(step_entry["registry_name"])
|
2025-07-07 12:01:34 +02:00
|
|
|
|
step_key = step_entry["registry_name"]
|
2025-07-03 14:11:28 +02:00
|
|
|
|
except KeyError as e:
|
|
|
|
|
|
raise ImportError(f"Failed to load processor step from registry. {str(e)}") from e
|
|
|
|
|
|
else:
|
|
|
|
|
|
# Fall back to module path loading for backward compatibility
|
|
|
|
|
|
full_class_path = step_entry["class"]
|
|
|
|
|
|
module_path, class_name = full_class_path.rsplit(".", 1)
|
|
|
|
|
|
|
|
|
|
|
|
# Import the module containing the step class
|
|
|
|
|
|
try:
|
|
|
|
|
|
module = importlib.import_module(module_path)
|
|
|
|
|
|
step_class = getattr(module, class_name)
|
2025-07-07 12:01:34 +02:00
|
|
|
|
step_key = class_name
|
2025-07-03 14:11:28 +02:00
|
|
|
|
except (ImportError, AttributeError) as e:
|
|
|
|
|
|
raise ImportError(
|
|
|
|
|
|
f"Failed to load processor step '{full_class_path}'. "
|
|
|
|
|
|
f"Make sure the module '{module_path}' is installed and contains class '{class_name}'. "
|
|
|
|
|
|
f"Consider registering the step using @ProcessorStepRegistry.register() for better portability. "
|
|
|
|
|
|
f"Error: {str(e)}"
|
|
|
|
|
|
) from e
|
|
|
|
|
|
|
|
|
|
|
|
# Instantiate the step with its config
|
|
|
|
|
|
try:
|
2025-07-07 12:01:34 +02:00
|
|
|
|
saved_cfg = step_entry.get("config", {})
|
|
|
|
|
|
step_overrides = overrides.get(step_key, {})
|
|
|
|
|
|
merged_cfg = {**saved_cfg, **step_overrides}
|
|
|
|
|
|
step_instance: ProcessorStep = step_class(**merged_cfg)
|
|
|
|
|
|
|
|
|
|
|
|
# Track which override keys were used
|
|
|
|
|
|
if step_key in override_keys:
|
|
|
|
|
|
override_keys.discard(step_key)
|
|
|
|
|
|
|
2025-07-03 14:11:28 +02:00
|
|
|
|
except Exception as e:
|
|
|
|
|
|
step_name = step_entry.get("registry_name", step_entry.get("class", "Unknown"))
|
|
|
|
|
|
raise ValueError(
|
|
|
|
|
|
f"Failed to instantiate processor step '{step_name}' with config: {step_entry.get('config', {})}. "
|
|
|
|
|
|
f"Error: {str(e)}"
|
|
|
|
|
|
) from e
|
|
|
|
|
|
|
|
|
|
|
|
# Load state if available
|
2025-07-02 17:29:58 +02:00
|
|
|
|
if "state_file" in step_entry and hasattr(step_instance, "load_state_dict"):
|
|
|
|
|
|
if Path(source).is_dir():
|
|
|
|
|
|
# Local path - read directly
|
|
|
|
|
|
state_path = str(base_path / step_entry["state_file"])
|
|
|
|
|
|
else:
|
|
|
|
|
|
# Hugging Face Hub - download the state file
|
2025-08-05 17:44:21 +02:00
|
|
|
|
state_path = hf_hub_download(
|
|
|
|
|
|
source,
|
|
|
|
|
|
step_entry["state_file"],
|
|
|
|
|
|
repo_type="model",
|
|
|
|
|
|
force_download=force_download,
|
|
|
|
|
|
resume_download=resume_download,
|
|
|
|
|
|
proxies=proxies,
|
|
|
|
|
|
token=token,
|
|
|
|
|
|
cache_dir=cache_dir,
|
|
|
|
|
|
local_files_only=local_files_only,
|
|
|
|
|
|
revision=revision,
|
|
|
|
|
|
)
|
2025-07-02 15:31:15 +00:00
|
|
|
|
|
2025-07-02 17:29:58 +02:00
|
|
|
|
step_instance.load_state_dict(load_file(state_path))
|
|
|
|
|
|
|
|
|
|
|
|
steps.append(step_instance)
|
|
|
|
|
|
|
2025-07-07 12:01:34 +02:00
|
|
|
|
# Check for unused override keys
|
|
|
|
|
|
if override_keys:
|
|
|
|
|
|
available_keys = []
|
2025-08-05 17:44:21 +02:00
|
|
|
|
for step_entry in loaded_config["steps"]:
|
2025-07-07 12:01:34 +02:00
|
|
|
|
if "registry_name" in step_entry:
|
|
|
|
|
|
available_keys.append(step_entry["registry_name"])
|
|
|
|
|
|
else:
|
|
|
|
|
|
full_class_path = step_entry["class"]
|
|
|
|
|
|
class_name = full_class_path.rsplit(".", 1)[1]
|
|
|
|
|
|
available_keys.append(class_name)
|
|
|
|
|
|
|
|
|
|
|
|
raise KeyError(
|
|
|
|
|
|
f"Override keys {list(override_keys)} do not match any step in the saved configuration. "
|
|
|
|
|
|
f"Available step keys: {available_keys}. "
|
|
|
|
|
|
f"Make sure override keys match exact step class names or registry names."
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-09-02 12:57:14 +02:00
|
|
|
|
return cls(
|
|
|
|
|
|
steps=steps,
|
2025-09-03 17:13:16 +02:00
|
|
|
|
name=loaded_config.get("name", "DataProcessorPipeline"),
|
2025-09-02 15:33:38 +02:00
|
|
|
|
to_transition=to_transition or batch_to_transition,
|
2025-09-02 12:57:14 +02:00
|
|
|
|
# Cast is necessary here: Same type-checker limitation as above.
|
|
|
|
|
|
# When to_output is None, we use the default which returns dict[str, Any].
|
|
|
|
|
|
# The cast ensures type consistency with the generic TOutput parameter.
|
2025-09-02 15:33:38 +02:00
|
|
|
|
to_output=to_output or cast(Callable[[EnvTransition], TOutput], transition_to_batch),
|
2025-09-02 12:57:14 +02:00
|
|
|
|
)
|
2025-07-02 17:29:58 +02:00
|
|
|
|
|
|
|
|
|
|
def __len__(self) -> int:
|
2025-07-03 14:11:28 +02:00
|
|
|
|
"""Return the number of steps in the processor."""
|
2025-07-02 17:29:58 +02:00
|
|
|
|
return len(self.steps)
|
|
|
|
|
|
|
2025-09-03 17:13:16 +02:00
|
|
|
|
def __getitem__(self, idx: int | slice) -> ProcessorStep | DataProcessorPipeline[TOutput]:
|
2025-07-02 17:29:58 +02:00
|
|
|
|
"""Indexing helper exposing underlying steps.
|
2025-07-03 14:11:28 +02:00
|
|
|
|
* ``int`` – returns the idx-th ProcessorStep.
|
2025-09-03 17:13:16 +02:00
|
|
|
|
* ``slice`` – returns a new DataProcessorPipeline with the sliced steps.
|
2025-07-02 17:29:58 +02:00
|
|
|
|
"""
|
|
|
|
|
|
if isinstance(idx, slice):
|
2025-09-03 17:13:16 +02:00
|
|
|
|
return DataProcessorPipeline(
|
2025-09-02 12:57:14 +02:00
|
|
|
|
steps=self.steps[idx],
|
|
|
|
|
|
name=self.name,
|
|
|
|
|
|
to_transition=self.to_transition,
|
|
|
|
|
|
to_output=self.to_output,
|
|
|
|
|
|
before_step_hooks=self.before_step_hooks.copy(),
|
|
|
|
|
|
after_step_hooks=self.after_step_hooks.copy(),
|
|
|
|
|
|
)
|
2025-07-02 17:29:58 +02:00
|
|
|
|
return self.steps[idx]
|
|
|
|
|
|
|
2025-07-22 10:41:22 +02:00
|
|
|
|
def register_before_step_hook(self, fn: Callable[[int, EnvTransition], None]):
|
2025-07-03 14:11:28 +02:00
|
|
|
|
"""Attach fn to be executed before every processor step."""
|
2025-07-02 17:29:58 +02:00
|
|
|
|
self.before_step_hooks.append(fn)
|
|
|
|
|
|
|
2025-07-22 10:41:22 +02:00
|
|
|
|
def unregister_before_step_hook(self, fn: Callable[[int, EnvTransition], None]):
|
2025-07-21 18:56:01 +02:00
|
|
|
|
"""Remove a previously registered before_step hook.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
fn: The exact function reference that was registered. Must be the same object.
|
|
|
|
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
|
|
ValueError: If the hook is not found in the registered hooks.
|
|
|
|
|
|
"""
|
|
|
|
|
|
try:
|
|
|
|
|
|
self.before_step_hooks.remove(fn)
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
|
raise ValueError(
|
|
|
|
|
|
f"Hook {fn} not found in before_step_hooks. Make sure to pass the exact same function reference."
|
|
|
|
|
|
) from None
|
|
|
|
|
|
|
2025-07-22 10:41:22 +02:00
|
|
|
|
def register_after_step_hook(self, fn: Callable[[int, EnvTransition], None]):
|
2025-07-03 14:11:28 +02:00
|
|
|
|
"""Attach fn to be executed after every processor step."""
|
2025-07-02 17:29:58 +02:00
|
|
|
|
self.after_step_hooks.append(fn)
|
|
|
|
|
|
|
2025-07-22 10:41:22 +02:00
|
|
|
|
def unregister_after_step_hook(self, fn: Callable[[int, EnvTransition], None]):
|
2025-07-21 18:56:01 +02:00
|
|
|
|
"""Remove a previously registered after_step hook.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
fn: The exact function reference that was registered. Must be the same object.
|
|
|
|
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
|
|
ValueError: If the hook is not found in the registered hooks.
|
|
|
|
|
|
"""
|
|
|
|
|
|
try:
|
|
|
|
|
|
self.after_step_hooks.remove(fn)
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
|
raise ValueError(
|
|
|
|
|
|
f"Hook {fn} not found in after_step_hooks. Make sure to pass the exact same function reference."
|
|
|
|
|
|
) from None
|
|
|
|
|
|
|
2025-07-02 17:29:58 +02:00
|
|
|
|
def reset(self):
|
|
|
|
|
|
"""Clear state in every step that implements ``reset()`` and fire registered hooks."""
|
|
|
|
|
|
for step in self.steps:
|
|
|
|
|
|
if hasattr(step, "reset"):
|
|
|
|
|
|
step.reset() # type: ignore[attr-defined]
|
2025-07-04 10:53:40 +02:00
|
|
|
|
|
2025-07-22 10:49:21 +02:00
|
|
|
|
def __repr__(self) -> str:
|
|
|
|
|
|
"""Return a readable string representation of the processor."""
|
|
|
|
|
|
step_names = [step.__class__.__name__ for step in self.steps]
|
|
|
|
|
|
|
|
|
|
|
|
if not step_names:
|
|
|
|
|
|
steps_repr = "steps=0: []"
|
|
|
|
|
|
elif len(step_names) <= 3:
|
|
|
|
|
|
steps_repr = f"steps={len(step_names)}: [{', '.join(step_names)}]"
|
|
|
|
|
|
else:
|
|
|
|
|
|
# Show first 2 and last 1 with ellipsis for long lists
|
|
|
|
|
|
displayed = f"{step_names[0]}, {step_names[1]}, ..., {step_names[-1]}"
|
|
|
|
|
|
steps_repr = f"steps={len(step_names)}: [{displayed}]"
|
|
|
|
|
|
|
|
|
|
|
|
parts = [f"name='{self.name}'", steps_repr]
|
|
|
|
|
|
|
2025-09-03 17:13:16 +02:00
|
|
|
|
return f"DataProcessorPipeline({', '.join(parts)})"
|
2025-07-22 10:49:21 +02:00
|
|
|
|
|
2025-07-31 16:29:48 +02:00
|
|
|
|
def __post_init__(self):
|
|
|
|
|
|
for i, step in enumerate(self.steps):
|
|
|
|
|
|
if not callable(step):
|
2025-08-31 20:38:52 +02:00
|
|
|
|
# TODO(steven): This should instead check isinstance(step, ProcessorStep), test need to be updated
|
2025-07-31 16:29:48 +02:00
|
|
|
|
raise TypeError(
|
|
|
|
|
|
f"Step {i} ({type(step).__name__}) must define __call__(transition) -> EnvTransition"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
Integrate pipeline and add phone teleop (#1681)
* Add normalization processor and related components
- Introduced `NormalizationProcessor` to handle both observation normalization and action unnormalization.
- Added `ObservationNormalizer` and `ActionUnnormalizer` classes for specific normalization tasks.
- Updated `__init__.py` to include the new `NormalizationProcessor` in the module exports.
- Enhanced `ObservationProcessor` with registration in the `ProcessorStepRegistry` for better modularity.
- Created `RenameProcessor` for renaming keys in observations, improving flexibility in data processing.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Enhance processing architecture with new components
- Added `RenameProcessor` to facilitate key renaming in observations, improving data handling flexibility.
- Updated `__init__.py` to include `RenameProcessor` in module exports.
- Refactored `NormalizationProcessor` and `ObservationNormalizer` to use `rsplit` for better key handling.
- Introduced comprehensive tests for `NormalizationProcessor` and `RenameProcessor` to ensure functionality and robustness.
* chore (docs): add docstring for processor
* fix (test): test factory
* fix(test): policies
* Update tests/processor/test_observation_processor.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
* chore(test): add suggestion made by copilot regarding numpy test
* fix(test): import issue
* Refactor normalization components and update tests
- Renamed `ObservationNormalizer` to `NormalizerProcessor` and `ActionUnnormalizer` to `UnnormalizerProcessor` for clarity.
- Consolidated normalization logic for both observations and actions into `NormalizerProcessor` and `UnnormalizerProcessor`.
- Updated tests to reflect the new class names and ensure proper functionality of normalization and unnormalization processes.
- Enhanced handling of missing statistics in normalization processes.
* chore (docstrin):Improve docstring for NormalizerProcessor
* feat (device processor): Implement device processor
* chore (batch handling): Enhance processing components with batch conversion utilities
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix(test): linting issue
* chore (output format): improves output format
* chore (type): add typing for multiprocess envs
* feat (overrides): Implement support for loading processors with parameter overrides
- Added the ability to provide non-serializable objects when loading processors from saved configurations using the `overrides` parameter.
- Enhanced error handling for invalid override keys and instantiation errors.
- Updated documentation and examples to illustrate the usage of overrides for both registered and unregistered steps.
- Added comprehensive tests to validate the new functionality and ensure backward compatibility.
* chore(normalization): addressing comments from copilot
* chore(learner): nit comment from copilot
* feat(pipeline): Enhance step_through method to support both tuple and dict inputs
* refactor(pipeline): Simplify observation and padding data handling in batch transitions
* Apply suggestions from code review
Co-authored-by: Simon Alibert <75076266+aliberts@users.noreply.github.com>
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Introduce ComplementaryDataProcessor for handling complementary data in transitions
* fix(ci): temporary fix on dataset deps version
* feat(processors): Introduce processors for various policy types
- Added `make_processor` function to create processor instances for different policy types, including `tdmpc`, `diffusion`, `act`, `vqbet`, `pi0`, `pi0fast`, `sac`, and `reward_classifier`.
- Implemented corresponding processor files for each policy type, encapsulating normalization and unnormalization steps.
- Updated existing policies to remove direct normalization dependencies, enhancing modularity and clarity.
- Enhanced test coverage to validate the integration of new processors with existing policy configurations.
* refactor(learner): Remove normalization from cached image features retrieval
- Simplified the retrieval of observation features by removing the normalization step from the `get_cached_image_features` method calls.
- This change enhances clarity and aligns with the recent updates to policy processors.
* refactor(policies): Remove unnormalization step from action predictions
- Eliminated the unnormalization of actions in both `TDMPCPolicy` and `VQBeTPolicy` classes to streamline action prediction.
- This change improves code clarity and aligns with recent updates to policy processors.
* feat(train): Integrate preprocessor into training pipeline
* refactor(train): Update preprocessor initialization to include dataset statistics
* refactor(policies): Enhance processor creation and add NaN detection hook
* refactor(train): Update memory pinning logic for mps compatibility
* feat: initial commit phone teleop
* ugly delta control
* use quaternion
* Refactor observation preprocessing to use a modular pipeline system
- Introduced `RobotPipeline` and `ObservationProcessor` for handling observation transformations.
- Updated `preprocess_observation` to maintain backward compatibility while leveraging the new pipeline.
- Added tests for the new processing components and ensured they match the original functionality.
- Removed hardcoded logic in favor of a more flexible, composable architecture.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor observation processing and improve modularity
- Updated `ObservationProcessor` to enhance the modular design for processing observations.
- Cleaned up imports and improved code readability by removing unnecessary lines and comments.
- Ensured backward compatibility while integrating new processing components.
- Added tests to validate the functionality of the updated processing architecture.
* Remove redundant tests for None observation and serialization methods in `test_observation_processor.py` to streamline the test suite and improve maintainability.
* Refactor processing architecture to use RobotProcessor
- Replaced instances of RobotPipeline with RobotProcessor across the codebase for improved modularity and clarity.
- Introduced ProcessorStepRegistry for better management of processing steps.
- Updated relevant documentation and tests to reflect the new processing structure.
- Enhanced the save/load functionality to support the new processor design.
- Added a model card template for RobotProcessor to facilitate sharing and documentation.
* Add RobotProcessor tutorial to documentation
- Introduced a new tutorial on using RobotProcessor for preprocessing robot data.
- Added a section in the table of contents for easy navigation to the new tutorial.
- The tutorial covers key concepts, real-world scenarios, and practical examples for effective use of the RobotProcessor pipeline.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add normalization processor and related components
- Introduced `NormalizationProcessor` to handle both observation normalization and action unnormalization.
- Added `ObservationNormalizer` and `ActionUnnormalizer` classes for specific normalization tasks.
- Updated `__init__.py` to include the new `NormalizationProcessor` in the module exports.
- Enhanced `ObservationProcessor` with registration in the `ProcessorStepRegistry` for better modularity.
- Created `RenameProcessor` for renaming keys in observations, improving flexibility in data processing.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Enhance processing architecture with new components
- Added `RenameProcessor` to facilitate key renaming in observations, improving data handling flexibility.
- Updated `__init__.py` to include `RenameProcessor` in module exports.
- Refactored `NormalizationProcessor` and `ObservationNormalizer` to use `rsplit` for better key handling.
- Introduced comprehensive tests for `NormalizationProcessor` and `RenameProcessor` to ensure functionality and robustness.
* chore (docs): add docstring for processor
* fix (test): test factory
* fix(test): policies
* Update tests/processor/test_observation_processor.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
* chore(test): add suggestion made by copilot regarding numpy test
* fix(test): import issue
* Refactor normalization components and update tests
- Renamed `ObservationNormalizer` to `NormalizerProcessor` and `ActionUnnormalizer` to `UnnormalizerProcessor` for clarity.
- Consolidated normalization logic for both observations and actions into `NormalizerProcessor` and `UnnormalizerProcessor`.
- Updated tests to reflect the new class names and ensure proper functionality of normalization and unnormalization processes.
- Enhanced handling of missing statistics in normalization processes.
* chore (docstrin):Improve docstring for NormalizerProcessor
* feat (device processor): Implement device processor
* chore (batch handling): Enhance processing components with batch conversion utilities
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix(test): linting issue
* chore (output format): improves output format
* chore (type): add typing for multiprocess envs
* feat (overrides): Implement support for loading processors with parameter overrides
- Added the ability to provide non-serializable objects when loading processors from saved configurations using the `overrides` parameter.
- Enhanced error handling for invalid override keys and instantiation errors.
- Updated documentation and examples to illustrate the usage of overrides for both registered and unregistered steps.
- Added comprehensive tests to validate the new functionality and ensure backward compatibility.
* chore(normalization): addressing comments from copilot
* chore(learner): nit comment from copilot
* feat(pipeline): Enhance step_through method to support both tuple and dict inputs
* refactor(pipeline): Simplify observation and padding data handling in batch transitions
* Apply suggestions from code review
Co-authored-by: Simon Alibert <75076266+aliberts@users.noreply.github.com>
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Introduce ComplementaryDataProcessor for handling complementary data in transitions
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Transition from tuple to dictionary format for EnvTransition
- Updated the EnvTransition structure to use a dictionary format instead of a tuple, enhancing readability and maintainability.
- Replaced instances of TransitionIndex with TransitionKey for accessing transition components.
- Adjusted related processing functions and tests to accommodate the new dictionary format, ensuring consistent handling of transitions across the codebase.
* refactor(observation_processor): Improve observation processing by using constants and simplifying pixel handling
- Introduced constants for observation keys to enhance readability.
- Streamlined the handling of the "pixels" key by copying observations first and processing images more clearly.
- Updated the environment state and agent position assignments to use the new constants, improving maintainability.
* feat(pipeline): Add hook unregistration functionality and enhance documentation
- Implemented methods to unregister before, after, and reset hooks in the RobotProcessor class, allowing for more flexible hook management.
- Enhanced documentation to clarify hook execution semantics and the implications of modifying transitions within hooks.
- Added comprehensive tests to verify the correct behavior of hook registration and unregistration, including error handling for non-existent hooks.
* refactor(pipeline): Clarify hook behavior and improve documentation
- Updated the RobotProcessor class to ensure hooks are strictly for observation and do not modify transitions, enhancing clarity and maintainability.
- Refactored hook registration methods to reflect the new behavior, ensuring they accept only functions that do not return modified transitions.
- Enhanced documentation to clearly outline the purpose of hooks and their execution semantics.
- Added tests to verify that hooks are not executed during the step_through method while ensuring they function correctly during the __call__ method.
* feat(pipeline): Add __repr__ method to RobotProcessor for improved readability
- Implemented a __repr__ method in the RobotProcessor class to provide a clear string representation of the processor, including step names and optional parameters like name and seed.
- Added comprehensive tests to validate the __repr__ output for various scenarios, including empty processors, single and multiple steps, custom names, and seed values.
- Ensured that the representation handles long lists of steps with truncation for better readability.
* chore(pipeline): Move _CFG_NAME along other class member
* refactor(pipeline): Utilize get_safe_torch_device for device assignment
- Replaced direct torch.device instantiation with get_safe_torch_device to ensure safe device handling.
- This change enhances code readability and maintains consistency in device management across the RobotProcessor class.
* refactor(pipeline): Enhance state filename generation and profiling method
- Updated state filename generation to use the registry name when available, improving clarity in saved files.
- Modified the profile_steps method to include a warmup_runs parameter, allowing for more controlled performance profiling.
- Ensured consistent conditions during profiling by deep copying transitions for each run, enhancing accuracy in timing results.
* chore(doc): address pip install commant lerobot that not exist yet
* feat(pipeline): Enhance configuration filename handling and state file naming
- Introduced support for custom configuration filenames in the `save_pretrained` method, allowing users to specify a filename instead of the default.
- Improved state file naming to include step indices, preventing conflicts when multiple processors of the same type are saved.
- Added automatic detection for configuration files when loading from a directory, with error handling for multiple files.
- Updated tests to validate new features, including custom filenames and automatic config detection.
* refactor(pipeline): Improve state file naming conventions for clarity and uniqueness
- Enhanced state file naming to include the processor's sanitized name, ensuring uniqueness when multiple processors are saved in the same directory.
- Updated tests to reflect changes in state file naming, verifying that filenames now include the processor name and step indices to prevent conflicts.
- Added a new test to validate state file naming when using multiple processors, ensuring distinct filenames for each processor's state files.
* docs(pipeline): Add clarification for repo name sanitization process
* feat(processors): Introduce processors for various policy types
- Added `make_processor` function to create processor instances for different policy types, including `tdmpc`, `diffusion`, `act`, `vqbet`, `pi0`, `pi0fast`, `sac`, and `reward_classifier`.
- Implemented corresponding processor files for each policy type, encapsulating normalization and unnormalization steps.
- Updated existing policies to remove direct normalization dependencies, enhancing modularity and clarity.
- Enhanced test coverage to validate the integration of new processors with existing policy configurations.
* refactor(learner): Remove normalization from cached image features retrieval
- Simplified the retrieval of observation features by removing the normalization step from the `get_cached_image_features` method calls.
- This change enhances clarity and aligns with the recent updates to policy processors.
* refactor(policies): Remove unnormalization step from action predictions
- Eliminated the unnormalization of actions in both `TDMPCPolicy` and `VQBeTPolicy` classes to streamline action prediction.
- This change improves code clarity and aligns with recent updates to policy processors.
* feat(train): Integrate preprocessor into training pipeline
* refactor(train): Update preprocessor initialization to include dataset statistics
* refactor(policies): Enhance processor creation and add NaN detection hook
* feat(record): Integrate RobotProcessor into recording loop and update policy handling
- Added support for RobotProcessor in the record_loop function to enhance data processing capabilities.
- Updated the logic to reset both policy and processor when provided, ensuring proper state management.
- Modified action prediction to utilize the processor, improving the overall functionality of the recording process.
- Adjusted the save_checkpoint function to include preprocessor state saving, enhancing checkpointing capabilities.
* feat(migration): Add script for migrating policy models with normalization layers
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(migrate): Enhance migration script to create preprocessor and postprocessor for policy models
- Updated the migration script to generate both a preprocessor and a postprocessor, improving the handling of normalization for training and inference.
- Added functionality to convert features to PolicyFeature objects, ensuring compatibility with the new processor architecture.
- Refined the extraction and removal of normalization statistics and layers, streamlining the migration process.
- Improved error handling for missing mandatory configuration fields during model instantiation.
* feat(migrate): Add model card generation and saving to migration script
- Implemented functionality to generate and save a model card for the migrated model, including metadata such as dataset repository ID, license, and tags.
- Enhanced the script to push the model card to the hub if requested, improving model documentation and accessibility.
- Refactored the saving process to ensure the model card is saved locally and uploaded correctly when pushing to the hub.
* feat(processor): Introduce ToBatchProcessor for handling observation batching
- Added ToBatchProcessor to ensure observations have proper batch dimensions for model processing.
- Implemented functionality to add batch dimensions to state and image observations as needed.
- Created comprehensive unit tests to validate the processor's behavior with various tensor dimensions and types.
- Ensured compatibility with existing transition keys and maintained the integrity of non-observation data.
* feat(processors): Add ToBatchProcessor to multiple policy processors
- Integrated ToBatchProcessor into various policy processors to handle observation batching.
- Updated make functions for act, diffusion, pi0, pi0fast, sac, smolvla, tdmpc, and vqbet processors to include the new batching functionality.
- Ensured consistency across all processor implementations for improved data handling.
* refactor(factory): Remove unused imports and NaN detection hook from processor creation
* feat(batch_processor): Enhance ToBatchProcessor to handle action batching
- Updated ToBatchProcessor to add batch dimensions to actions in addition to observations.
- Implemented separate methods for processing observations and actions, improving code readability.
- Added comprehensive unit tests to validate action batching functionality across various tensor dimensions and types.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(factory): Enhance make_processor to support preprocessor and postprocessor configuration
- Introduced ProcessorConfigKwargs TypedDict for better type safety in processor configuration.
- Updated make_processor to accept preprocessor and postprocessor configuration filenames, improving flexibility in processor instantiation.
- Refactored the loading of pretrained processors to utilize the new configuration options.
* refactor(factory): Clean up imports in factory.py
- Removed unused import of IdentityProcessor to streamline the code.
* feat(migrate): Extend load_model_from_hub to include train configuration
- Updated load_model_from_hub to return the train configuration alongside the model state_dict and config.
- Modified main function to handle the additional train configuration when loading models from both the hub and local paths.
- Adjusted dataset_repo_id extraction to utilize the train configuration for improved accuracy.
* refactor(record): Rename processor parameters and update processing logic
- Renamed `processor` to `preprocessor` and added `postprocessor` parameter for clarity.
- Updated the `record_loop` and `predict_action` functions to utilize the new preprocessor and postprocessor, enhancing the processing flow.
- Ensured compatibility with existing functionality while improving code readability.
* feat(batch_processor): Add task field processing to ToBatchProcessor
- Enhanced ToBatchProcessor to wrap string tasks in a list, adding batch dimensions for compatibility with model inference.
- Implemented a new method for processing complementary data, ensuring that task values are correctly handled as either strings or lists of strings.
- Added comprehensive unit tests to validate task processing, including edge cases and in-place mutation of complementary data.
* feat(normalization): Implement IDENTITY mode for normalization and unnormalization
- Enhanced NormalizerProcessor and UnnormalizerProcessor to support IDENTITY mode, allowing features to bypass normalization when specified.
- Updated processing logic to check normalization modes and handle missing statistics gracefully.
- Added comprehensive unit tests to validate IDENTITY mode functionality for both observations and actions, ensuring correct behavior across various scenarios.
- Improved error handling for unsupported normalization modes.
* fix(rebase): remove residual normalization layer:
* refactor(diffusion): remove normalization layer from input processing
* Add debug + calib
* cleanup
* Add pipeline
* fix int
* Add record example
* nit
* Add feature contract to pipelinestep and pipeline
* Add tests
* Add processor tests
* PR feedback
* encorperate pr feedback
* type in doc
* oops
* cleaned up steps and integrated pipeline with feature_contract
* refactor steps and robot to pipeline
* cleanup pipeline
* cleanup code further
* make it run
* feat(processors): Introduce processors for various policy types
- Added `make_processor` function to create processor instances for different policy types, including `tdmpc`, `diffusion`, `act`, `vqbet`, `pi0`, `pi0fast`, `sac`, and `reward_classifier`.
- Implemented corresponding processor files for each policy type, encapsulating normalization and unnormalization steps.
- Updated existing policies to remove direct normalization dependencies, enhancing modularity and clarity.
- Enhanced test coverage to validate the integration of new processors with existing policy configurations.
* refactor(learner): Remove normalization from cached image features retrieval
- Simplified the retrieval of observation features by removing the normalization step from the `get_cached_image_features` method calls.
- This change enhances clarity and aligns with the recent updates to policy processors.
* refactor(policies): Remove unnormalization step from action predictions
- Eliminated the unnormalization of actions in both `TDMPCPolicy` and `VQBeTPolicy` classes to streamline action prediction.
- This change improves code clarity and aligns with recent updates to policy processors.
* feat(train): Integrate preprocessor into training pipeline
* refactor(train): Update preprocessor initialization to include dataset statistics
* refactor(policies): Enhance processor creation and add NaN detection hook
* feat(record): Integrate RobotProcessor into recording loop and update policy handling
- Added support for RobotProcessor in the record_loop function to enhance data processing capabilities.
- Updated the logic to reset both policy and processor when provided, ensuring proper state management.
- Modified action prediction to utilize the processor, improving the overall functionality of the recording process.
- Adjusted the save_checkpoint function to include preprocessor state saving, enhancing checkpointing capabilities.
* feat(migration): Add script for migrating policy models with normalization layers
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(migrate): Enhance migration script to create preprocessor and postprocessor for policy models
- Updated the migration script to generate both a preprocessor and a postprocessor, improving the handling of normalization for training and inference.
- Added functionality to convert features to PolicyFeature objects, ensuring compatibility with the new processor architecture.
- Refined the extraction and removal of normalization statistics and layers, streamlining the migration process.
- Improved error handling for missing mandatory configuration fields during model instantiation.
* feat(migrate): Add model card generation and saving to migration script
- Implemented functionality to generate and save a model card for the migrated model, including metadata such as dataset repository ID, license, and tags.
- Enhanced the script to push the model card to the hub if requested, improving model documentation and accessibility.
- Refactored the saving process to ensure the model card is saved locally and uploaded correctly when pushing to the hub.
* feat(processor): Introduce ToBatchProcessor for handling observation batching
- Added ToBatchProcessor to ensure observations have proper batch dimensions for model processing.
- Implemented functionality to add batch dimensions to state and image observations as needed.
- Created comprehensive unit tests to validate the processor's behavior with various tensor dimensions and types.
- Ensured compatibility with existing transition keys and maintained the integrity of non-observation data.
* feat(processors): Add ToBatchProcessor to multiple policy processors
- Integrated ToBatchProcessor into various policy processors to handle observation batching.
- Updated make functions for act, diffusion, pi0, pi0fast, sac, smolvla, tdmpc, and vqbet processors to include the new batching functionality.
- Ensured consistency across all processor implementations for improved data handling.
* refactor(factory): Remove unused imports and NaN detection hook from processor creation
* feat(batch_processor): Enhance ToBatchProcessor to handle action batching
- Updated ToBatchProcessor to add batch dimensions to actions in addition to observations.
- Implemented separate methods for processing observations and actions, improving code readability.
- Added comprehensive unit tests to validate action batching functionality across various tensor dimensions and types.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(factory): Enhance make_processor to support preprocessor and postprocessor configuration
- Introduced ProcessorConfigKwargs TypedDict for better type safety in processor configuration.
- Updated make_processor to accept preprocessor and postprocessor configuration filenames, improving flexibility in processor instantiation.
- Refactored the loading of pretrained processors to utilize the new configuration options.
* refactor(factory): Clean up imports in factory.py
- Removed unused import of IdentityProcessor to streamline the code.
* feat(migrate): Extend load_model_from_hub to include train configuration
- Updated load_model_from_hub to return the train configuration alongside the model state_dict and config.
- Modified main function to handle the additional train configuration when loading models from both the hub and local paths.
- Adjusted dataset_repo_id extraction to utilize the train configuration for improved accuracy.
* refactor(record): Rename processor parameters and update processing logic
- Renamed `processor` to `preprocessor` and added `postprocessor` parameter for clarity.
- Updated the `record_loop` and `predict_action` functions to utilize the new preprocessor and postprocessor, enhancing the processing flow.
- Ensured compatibility with existing functionality while improving code readability.
* feat(batch_processor): Add task field processing to ToBatchProcessor
- Enhanced ToBatchProcessor to wrap string tasks in a list, adding batch dimensions for compatibility with model inference.
- Implemented a new method for processing complementary data, ensuring that task values are correctly handled as either strings or lists of strings.
- Added comprehensive unit tests to validate task processing, including edge cases and in-place mutation of complementary data.
* feat(normalization): Implement IDENTITY mode for normalization and unnormalization
- Enhanced NormalizerProcessor and UnnormalizerProcessor to support IDENTITY mode, allowing features to bypass normalization when specified.
- Updated processing logic to check normalization modes and handle missing statistics gracefully.
- Added comprehensive unit tests to validate IDENTITY mode functionality for both observations and actions, ensuring correct behavior across various scenarios.
- Improved error handling for unsupported normalization modes.
* fix(rebase): remove residual normalization layer:
* refactor(diffusion): remove normalization layer from input processing
* refactor(normalization): Remove unused state dict transformation methods and streamline imports
- Eliminated the _transform_state_dict_keys and _load_as_safetensor methods from PI0Policy, simplifying the model loading process.
- Cleaned up imports in modeling_pi0.py by removing log_model_loading_keys and init_logging.
- Updated TDMPCPolicy and VQBeTPolicy to handle action removal from batches during offline evaluation.
- Introduced hotswap_stats function in normalize_processor.py to update normalization statistics dynamically, with corresponding tests to ensure functionality.
* refactor(normalization): Clean up imports in normalize_processor.py
* feat(batch_processor): Add feature_contract method to ToBatchProcessor
- Introduced feature_contract method that returns features without modification, maintaining the no-op behavior of the processor.
- This addition enhances the flexibility of the ToBatchProcessor for future feature processing needs.
* fix(dependencies): Update transformers dependency constraint to allow only versions up to 4.52.0
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(tokenizer): Introduce TokenizerProcessor for text tokenization
- Added TokenizerProcessor class to handle tokenization of task strings using Hugging Face's AutoTokenizer.
- Supports both string and list inputs, with customizable parameters for task key, output key, and tokenization settings.
- Implemented comprehensive unit tests to validate functionality, including handling of various input scenarios and integration with RobotProcessor.
- Updated types.py to include LANGUAGE feature type and modified __init__.py to register the new processor.
* feat(language): Enhance language processing in TokenizerProcessor
- Added OBS_LANGUAGE constant to define the observation language key.
- Updated TokenizerProcessor to store tokenized task data in the observation dictionary, ensuring compatibility with the new language feature.
- Introduced Pi0NewLineProcessor to append newlines to tasks for proper tokenization.
- Modified tests to validate the integration of language tokens and attention masks in the observation structure.
* feat(tokenizer): Add padding configuration to TokenizerProcessor
- Introduced `padding_side` parameter to the TokenizerProcessor for customizable padding direction.
- Updated the `make_pi0_processor` function to include the new padding configuration.
- Enhanced unit tests to validate the functionality of the `padding_side` parameter in various scenarios.
* feat(processor): Add state management methods to Pi0NewLineProcessor
* feat(normalization): Track normalization and unnormalization info in complementary data
- Updated NormalizerProcessor and UnnormalizerProcessor to accept additional parameters for tracking normalization modes.
- Enhanced the __call__ methods to store normalization and unnormalization information in the complementary data of transitions.
- Added unit tests to verify the correct tracking of normalization info, including scenarios with missing stats and selective normalization keys.
* feat(factory): Add preprocessor and postprocessor overrides to ProcessorConfigKwargs
- Updated ProcessorConfigKwargs to include optional overrides for preprocessor and postprocessor configurations.
- Enhanced the make_processor function to utilize the new overrides, allowing for more flexible processor initialization.
* feat(processors): Integrate RenameProcessor into various processor configurations
- Added RenameProcessor to the input steps of multiple processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Consolidated normalization features from input and output into a single NormalizerProcessor for improved efficiency.
- Updated the input steps to ensure compatibility with the new RenameProcessor integration.
* Do some todos and cleanup
* change feature_contract to dataset_features
* use one method for conversion pipeline output to add_frame dict and use base processors where possible
* Add back in and use record_loop
* update todo
* rename to_dataset_frame
* feat(smolvla): Refactor language processing and introduce new line processor (#1658)
- Removed the prepare_language method and directly accessed language tokens and masks from the batch using the OBS_LANGUAGE constant.
- Added SmolVLANewLineProcessor to ensure tasks end with a newline, enhancing tokenization compatibility.
- Updated the make_smolvla_processor function to include the new line processor and tokenizer processor for improved input handling.
* feat(processors): Integrate DeviceProcessor into multiple processor configurations
- Added DeviceProcessor to the input and output steps of various processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_pi0fast_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Enhanced the DeviceProcessor class with state management methods and ensured compatibility with existing processor pipelines.
- Introduced unit tests for DeviceProcessor to validate functionality across different scenarios, including CPU and CUDA operations.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* fix reference frame
* refactor(pipeline): Remove to() method for device management
- Eliminated the to() method from RobotProcessor, which was responsible for moving tensor states to specified devices.
- Removed associated unit tests that validated the functionality of the to() method across various scenarios.
- Streamlined the pipeline code by focusing on other device management strategies.
* feat(processor): Enhance DeviceProcessor with float dtype conversion
- Added support for optional float dtype conversion in DeviceProcessor, allowing tensors to be converted to specified floating-point types while preserving non-float types.
- Implemented validation for float dtype input and updated the processor's configuration methods to include float dtype.
- Refactored tensor processing logic to streamline device movement and dtype conversion.
- Introduced comprehensive unit tests to validate the new float dtype functionality across various scenarios.
* update data visualization
* update teleop example
* fix record bugs
* Add replay
* Not code
* feature(pipeline): port tokenizer pipeline for VLA (#1645)
* feat(tokenizer): Introduce TokenizerProcessor for text tokenization
- Added TokenizerProcessor class to handle tokenization of task strings using Hugging Face's AutoTokenizer.
- Supports both string and list inputs, with customizable parameters for task key, output key, and tokenization settings.
- Implemented comprehensive unit tests to validate functionality, including handling of various input scenarios and integration with RobotProcessor.
- Updated types.py to include LANGUAGE feature type and modified __init__.py to register the new processor.
* feat(language): Enhance language processing in TokenizerProcessor
- Added OBS_LANGUAGE constant to define the observation language key.
- Updated TokenizerProcessor to store tokenized task data in the observation dictionary, ensuring compatibility with the new language feature.
- Introduced Pi0NewLineProcessor to append newlines to tasks for proper tokenization.
- Modified tests to validate the integration of language tokens and attention masks in the observation structure.
* feat(tokenizer): Add padding configuration to TokenizerProcessor
- Introduced `padding_side` parameter to the TokenizerProcessor for customizable padding direction.
- Updated the `make_pi0_processor` function to include the new padding configuration.
- Enhanced unit tests to validate the functionality of the `padding_side` parameter in various scenarios.
* feat(processor): Add state management methods to Pi0NewLineProcessor
* feat(normalization): Track normalization and unnormalization info in complementary data
- Updated NormalizerProcessor and UnnormalizerProcessor to accept additional parameters for tracking normalization modes.
- Enhanced the __call__ methods to store normalization and unnormalization information in the complementary data of transitions.
- Added unit tests to verify the correct tracking of normalization info, including scenarios with missing stats and selective normalization keys.
* feat(factory): Add preprocessor and postprocessor overrides to ProcessorConfigKwargs
- Updated ProcessorConfigKwargs to include optional overrides for preprocessor and postprocessor configurations.
- Enhanced the make_processor function to utilize the new overrides, allowing for more flexible processor initialization.
* feat(processors): Integrate RenameProcessor into various processor configurations
- Added RenameProcessor to the input steps of multiple processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Consolidated normalization features from input and output into a single NormalizerProcessor for improved efficiency.
- Updated the input steps to ensure compatibility with the new RenameProcessor integration.
* feat(smolvla): Refactor language processing and introduce new line processor (#1658)
- Removed the prepare_language method and directly accessed language tokens and masks from the batch using the OBS_LANGUAGE constant.
- Added SmolVLANewLineProcessor to ensure tasks end with a newline, enhancing tokenization compatibility.
- Updated the make_smolvla_processor function to include the new line processor and tokenizer processor for improved input handling.
* feture(policies): add device processor (#1659)
* feat(processors): Integrate DeviceProcessor into multiple processor configurations
- Added DeviceProcessor to the input and output steps of various processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_pi0fast_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Enhanced the DeviceProcessor class with state management methods and ensured compatibility with existing processor pipelines.
- Introduced unit tests for DeviceProcessor to validate functionality across different scenarios, including CPU and CUDA operations.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Remove to() method for device management
- Eliminated the to() method from RobotProcessor, which was responsible for moving tensor states to specified devices.
- Removed associated unit tests that validated the functionality of the to() method across various scenarios.
- Streamlined the pipeline code by focusing on other device management strategies.
* feat(processor): Enhance DeviceProcessor with float dtype conversion
- Added support for optional float dtype conversion in DeviceProcessor, allowing tensors to be converted to specified floating-point types while preserving non-float types.
- Implemented validation for float dtype input and updated the processor's configuration methods to include float dtype.
- Refactored tensor processing logic to streamline device movement and dtype conversion.
- Introduced comprehensive unit tests to validate the new float dtype functionality across various scenarios.
* feat(policies): Add new line processors and update module exports
* feat(processor): Enhance batch and device processors to handle index and task_index fields
- Added logic to ToBatchProcessor for unsqueezing 0D tensors for index and task_index fields, ensuring they are processed as 1D tensors.
- Updated DeviceProcessor to process index and task_index fields in complementary data, preserving their tensor types and ensuring non-tensor fields remain unchanged.
- Enhanced unit tests to validate the correct handling of index and task_index fields across various scenarios, including device compatibility and dtype preservation.
* Add eval script
* fix `q_curr` in InverseKinematicsEEToJoints to the IK solution
* feat(processors): Introduce processors for various policy types
- Added `make_processor` function to create processor instances for different policy types, including `tdmpc`, `diffusion`, `act`, `vqbet`, `pi0`, `pi0fast`, `sac`, and `reward_classifier`.
- Implemented corresponding processor files for each policy type, encapsulating normalization and unnormalization steps.
- Updated existing policies to remove direct normalization dependencies, enhancing modularity and clarity.
- Enhanced test coverage to validate the integration of new processors with existing policy configurations.
* refactor(learner): Remove normalization from cached image features retrieval
- Simplified the retrieval of observation features by removing the normalization step from the `get_cached_image_features` method calls.
- This change enhances clarity and aligns with the recent updates to policy processors.
* refactor(policies): Remove unnormalization step from action predictions
- Eliminated the unnormalization of actions in both `TDMPCPolicy` and `VQBeTPolicy` classes to streamline action prediction.
- This change improves code clarity and aligns with recent updates to policy processors.
* feat(train): Integrate preprocessor into training pipeline
* refactor(train): Update preprocessor initialization to include dataset statistics
* refactor(policies): Enhance processor creation and add NaN detection hook
* feat(record): Integrate RobotProcessor into recording loop and update policy handling
- Added support for RobotProcessor in the record_loop function to enhance data processing capabilities.
- Updated the logic to reset both policy and processor when provided, ensuring proper state management.
- Modified action prediction to utilize the processor, improving the overall functionality of the recording process.
- Adjusted the save_checkpoint function to include preprocessor state saving, enhancing checkpointing capabilities.
* feat(migration): Add script for migrating policy models with normalization layers
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(migrate): Enhance migration script to create preprocessor and postprocessor for policy models
- Updated the migration script to generate both a preprocessor and a postprocessor, improving the handling of normalization for training and inference.
- Added functionality to convert features to PolicyFeature objects, ensuring compatibility with the new processor architecture.
- Refined the extraction and removal of normalization statistics and layers, streamlining the migration process.
- Improved error handling for missing mandatory configuration fields during model instantiation.
* feat(migrate): Add model card generation and saving to migration script
- Implemented functionality to generate and save a model card for the migrated model, including metadata such as dataset repository ID, license, and tags.
- Enhanced the script to push the model card to the hub if requested, improving model documentation and accessibility.
- Refactored the saving process to ensure the model card is saved locally and uploaded correctly when pushing to the hub.
* feat(processor): Introduce ToBatchProcessor for handling observation batching
- Added ToBatchProcessor to ensure observations have proper batch dimensions for model processing.
- Implemented functionality to add batch dimensions to state and image observations as needed.
- Created comprehensive unit tests to validate the processor's behavior with various tensor dimensions and types.
- Ensured compatibility with existing transition keys and maintained the integrity of non-observation data.
* feat(processors): Add ToBatchProcessor to multiple policy processors
- Integrated ToBatchProcessor into various policy processors to handle observation batching.
- Updated make functions for act, diffusion, pi0, pi0fast, sac, smolvla, tdmpc, and vqbet processors to include the new batching functionality.
- Ensured consistency across all processor implementations for improved data handling.
* refactor(factory): Remove unused imports and NaN detection hook from processor creation
* feat(batch_processor): Enhance ToBatchProcessor to handle action batching
- Updated ToBatchProcessor to add batch dimensions to actions in addition to observations.
- Implemented separate methods for processing observations and actions, improving code readability.
- Added comprehensive unit tests to validate action batching functionality across various tensor dimensions and types.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(factory): Enhance make_processor to support preprocessor and postprocessor configuration
- Introduced ProcessorConfigKwargs TypedDict for better type safety in processor configuration.
- Updated make_processor to accept preprocessor and postprocessor configuration filenames, improving flexibility in processor instantiation.
- Refactored the loading of pretrained processors to utilize the new configuration options.
* refactor(factory): Clean up imports in factory.py
- Removed unused import of IdentityProcessor to streamline the code.
* feat(migrate): Extend load_model_from_hub to include train configuration
- Updated load_model_from_hub to return the train configuration alongside the model state_dict and config.
- Modified main function to handle the additional train configuration when loading models from both the hub and local paths.
- Adjusted dataset_repo_id extraction to utilize the train configuration for improved accuracy.
* refactor(record): Rename processor parameters and update processing logic
- Renamed `processor` to `preprocessor` and added `postprocessor` parameter for clarity.
- Updated the `record_loop` and `predict_action` functions to utilize the new preprocessor and postprocessor, enhancing the processing flow.
- Ensured compatibility with existing functionality while improving code readability.
* feat(batch_processor): Add task field processing to ToBatchProcessor
- Enhanced ToBatchProcessor to wrap string tasks in a list, adding batch dimensions for compatibility with model inference.
- Implemented a new method for processing complementary data, ensuring that task values are correctly handled as either strings or lists of strings.
- Added comprehensive unit tests to validate task processing, including edge cases and in-place mutation of complementary data.
* feat(normalization): Implement IDENTITY mode for normalization and unnormalization
- Enhanced NormalizerProcessor and UnnormalizerProcessor to support IDENTITY mode, allowing features to bypass normalization when specified.
- Updated processing logic to check normalization modes and handle missing statistics gracefully.
- Added comprehensive unit tests to validate IDENTITY mode functionality for both observations and actions, ensuring correct behavior across various scenarios.
- Improved error handling for unsupported normalization modes.
* fix(rebase): remove residual normalization layer:
* refactor(diffusion): remove normalization layer from input processing
* refactor(normalization): Remove unused state dict transformation methods and streamline imports
- Eliminated the _transform_state_dict_keys and _load_as_safetensor methods from PI0Policy, simplifying the model loading process.
- Cleaned up imports in modeling_pi0.py by removing log_model_loading_keys and init_logging.
- Updated TDMPCPolicy and VQBeTPolicy to handle action removal from batches during offline evaluation.
- Introduced hotswap_stats function in normalize_processor.py to update normalization statistics dynamically, with corresponding tests to ensure functionality.
* refactor(normalization): Clean up imports in normalize_processor.py
* feat(batch_processor): Add feature_contract method to ToBatchProcessor
- Introduced feature_contract method that returns features without modification, maintaining the no-op behavior of the processor.
- This addition enhances the flexibility of the ToBatchProcessor for future feature processing needs.
* fix(dependencies): Update transformers dependency constraint to allow only versions up to 4.52.0
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feature(pipeline): port tokenizer pipeline for VLA (#1645)
* feat(tokenizer): Introduce TokenizerProcessor for text tokenization
- Added TokenizerProcessor class to handle tokenization of task strings using Hugging Face's AutoTokenizer.
- Supports both string and list inputs, with customizable parameters for task key, output key, and tokenization settings.
- Implemented comprehensive unit tests to validate functionality, including handling of various input scenarios and integration with RobotProcessor.
- Updated types.py to include LANGUAGE feature type and modified __init__.py to register the new processor.
* feat(language): Enhance language processing in TokenizerProcessor
- Added OBS_LANGUAGE constant to define the observation language key.
- Updated TokenizerProcessor to store tokenized task data in the observation dictionary, ensuring compatibility with the new language feature.
- Introduced Pi0NewLineProcessor to append newlines to tasks for proper tokenization.
- Modified tests to validate the integration of language tokens and attention masks in the observation structure.
* feat(tokenizer): Add padding configuration to TokenizerProcessor
- Introduced `padding_side` parameter to the TokenizerProcessor for customizable padding direction.
- Updated the `make_pi0_processor` function to include the new padding configuration.
- Enhanced unit tests to validate the functionality of the `padding_side` parameter in various scenarios.
* feat(processor): Add state management methods to Pi0NewLineProcessor
* feat(normalization): Track normalization and unnormalization info in complementary data
- Updated NormalizerProcessor and UnnormalizerProcessor to accept additional parameters for tracking normalization modes.
- Enhanced the __call__ methods to store normalization and unnormalization information in the complementary data of transitions.
- Added unit tests to verify the correct tracking of normalization info, including scenarios with missing stats and selective normalization keys.
* feat(factory): Add preprocessor and postprocessor overrides to ProcessorConfigKwargs
- Updated ProcessorConfigKwargs to include optional overrides for preprocessor and postprocessor configurations.
- Enhanced the make_processor function to utilize the new overrides, allowing for more flexible processor initialization.
* feat(processors): Integrate RenameProcessor into various processor configurations
- Added RenameProcessor to the input steps of multiple processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Consolidated normalization features from input and output into a single NormalizerProcessor for improved efficiency.
- Updated the input steps to ensure compatibility with the new RenameProcessor integration.
* feat(smolvla): Refactor language processing and introduce new line processor (#1658)
- Removed the prepare_language method and directly accessed language tokens and masks from the batch using the OBS_LANGUAGE constant.
- Added SmolVLANewLineProcessor to ensure tasks end with a newline, enhancing tokenization compatibility.
- Updated the make_smolvla_processor function to include the new line processor and tokenizer processor for improved input handling.
* feture(policies): add device processor (#1659)
* feat(processors): Integrate DeviceProcessor into multiple processor configurations
- Added DeviceProcessor to the input and output steps of various processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_pi0fast_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Enhanced the DeviceProcessor class with state management methods and ensured compatibility with existing processor pipelines.
- Introduced unit tests for DeviceProcessor to validate functionality across different scenarios, including CPU and CUDA operations.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Remove to() method for device management
- Eliminated the to() method from RobotProcessor, which was responsible for moving tensor states to specified devices.
- Removed associated unit tests that validated the functionality of the to() method across various scenarios.
- Streamlined the pipeline code by focusing on other device management strategies.
* feat(processor): Enhance DeviceProcessor with float dtype conversion
- Added support for optional float dtype conversion in DeviceProcessor, allowing tensors to be converted to specified floating-point types while preserving non-float types.
- Implemented validation for float dtype input and updated the processor's configuration methods to include float dtype.
- Refactored tensor processing logic to streamline device movement and dtype conversion.
- Introduced comprehensive unit tests to validate the new float dtype functionality across various scenarios.
* feat(policies): Add new line processors and update module exports
* feat(processor): Enhance batch and device processors to handle index and task_index fields
- Added logic to ToBatchProcessor for unsqueezing 0D tensors for index and task_index fields, ensuring they are processed as 1D tensors.
- Updated DeviceProcessor to process index and task_index fields in complementary data, preserving their tensor types and ensuring non-tensor fields remain unchanged.
- Enhanced unit tests to validate the correct handling of index and task_index fields across various scenarios, including device compatibility and dtype preservation.
* refactor(processors): Standardize processor naming conventions
- Updated processor names across various files to use a consistent "robot_preprocessor" and "robot_postprocessor" format.
- Modified the make_processor functions in factory, act, diffusion, pi0, pi0fast, sac, smolvla, tdmpc, and vqbet to reflect the new naming scheme.
- Enhanced the pipeline configuration to align with the updated processor names, improving clarity and maintainability.
* refactor(factory): Update processor configuration and type hints
- Changed return type of get_policy_class to type[PreTrainedPolicy] for improved type safety.
- Enhanced make_processor function to utilize dataset_stats in processor creation for better flexibility.
- Updated ProcessorConfigKwargs to include dataset_stats, allowing for more comprehensive processor configurations.
- Streamlined processor initialization by removing unnecessary kwargs and ensuring clarity in processor type handling.
* Fix eval and android gripper
* add some tests
* refactor(factory, pi0fast): Update processor function names and parameters
- Renamed make_pi0_processor to make_pi0fast_processor for clarity and consistency.
- Updated parameter names in the factory's make_processor function to use pretrained_model_name_or_path instead of source, enhancing readability and alignment with naming conventions.
* fix(train.py) push postprocessor with preprocessor
- Add preprocesser policy overrides for device and rename_map
- Add rename_map to DatasetRecordConfig (record.py)
* Cleanup pr
* fix more git diff pr issues
* add path as type in save_pretrained
* small nit
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* rename test file
* fix: make dataset_features/feature_contract is optional
* fix tests
* Encorperate pr feedback
* clean up record.py
* add ascii art, fix normal record
* remove merge issues
* fix merge
* remove features
* Add feedback PR
* fix last 4 tests
* remove features check
* rename to transform_features
* add transform_features
* fix lekiwi eval and update eval api example
---------
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
Signed-off-by: Pepijn <138571049+pkooij@users.noreply.github.com>
Co-authored-by: Adil Zouitine <adilzouitinegm@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Simon Alibert <75076266+aliberts@users.noreply.github.com>
Co-authored-by: Michel Aractingi <michel.aractingi@huggingface.co>
2025-08-07 16:13:34 +02:00
|
|
|
|
def transform_features(self, initial_features: dict[str, PolicyFeature]) -> dict[str, PolicyFeature]:
|
2025-07-31 16:29:48 +02:00
|
|
|
|
"""
|
Integrate pipeline and add phone teleop (#1681)
* Add normalization processor and related components
- Introduced `NormalizationProcessor` to handle both observation normalization and action unnormalization.
- Added `ObservationNormalizer` and `ActionUnnormalizer` classes for specific normalization tasks.
- Updated `__init__.py` to include the new `NormalizationProcessor` in the module exports.
- Enhanced `ObservationProcessor` with registration in the `ProcessorStepRegistry` for better modularity.
- Created `RenameProcessor` for renaming keys in observations, improving flexibility in data processing.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Enhance processing architecture with new components
- Added `RenameProcessor` to facilitate key renaming in observations, improving data handling flexibility.
- Updated `__init__.py` to include `RenameProcessor` in module exports.
- Refactored `NormalizationProcessor` and `ObservationNormalizer` to use `rsplit` for better key handling.
- Introduced comprehensive tests for `NormalizationProcessor` and `RenameProcessor` to ensure functionality and robustness.
* chore (docs): add docstring for processor
* fix (test): test factory
* fix(test): policies
* Update tests/processor/test_observation_processor.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
* chore(test): add suggestion made by copilot regarding numpy test
* fix(test): import issue
* Refactor normalization components and update tests
- Renamed `ObservationNormalizer` to `NormalizerProcessor` and `ActionUnnormalizer` to `UnnormalizerProcessor` for clarity.
- Consolidated normalization logic for both observations and actions into `NormalizerProcessor` and `UnnormalizerProcessor`.
- Updated tests to reflect the new class names and ensure proper functionality of normalization and unnormalization processes.
- Enhanced handling of missing statistics in normalization processes.
* chore (docstrin):Improve docstring for NormalizerProcessor
* feat (device processor): Implement device processor
* chore (batch handling): Enhance processing components with batch conversion utilities
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix(test): linting issue
* chore (output format): improves output format
* chore (type): add typing for multiprocess envs
* feat (overrides): Implement support for loading processors with parameter overrides
- Added the ability to provide non-serializable objects when loading processors from saved configurations using the `overrides` parameter.
- Enhanced error handling for invalid override keys and instantiation errors.
- Updated documentation and examples to illustrate the usage of overrides for both registered and unregistered steps.
- Added comprehensive tests to validate the new functionality and ensure backward compatibility.
* chore(normalization): addressing comments from copilot
* chore(learner): nit comment from copilot
* feat(pipeline): Enhance step_through method to support both tuple and dict inputs
* refactor(pipeline): Simplify observation and padding data handling in batch transitions
* Apply suggestions from code review
Co-authored-by: Simon Alibert <75076266+aliberts@users.noreply.github.com>
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Introduce ComplementaryDataProcessor for handling complementary data in transitions
* fix(ci): temporary fix on dataset deps version
* feat(processors): Introduce processors for various policy types
- Added `make_processor` function to create processor instances for different policy types, including `tdmpc`, `diffusion`, `act`, `vqbet`, `pi0`, `pi0fast`, `sac`, and `reward_classifier`.
- Implemented corresponding processor files for each policy type, encapsulating normalization and unnormalization steps.
- Updated existing policies to remove direct normalization dependencies, enhancing modularity and clarity.
- Enhanced test coverage to validate the integration of new processors with existing policy configurations.
* refactor(learner): Remove normalization from cached image features retrieval
- Simplified the retrieval of observation features by removing the normalization step from the `get_cached_image_features` method calls.
- This change enhances clarity and aligns with the recent updates to policy processors.
* refactor(policies): Remove unnormalization step from action predictions
- Eliminated the unnormalization of actions in both `TDMPCPolicy` and `VQBeTPolicy` classes to streamline action prediction.
- This change improves code clarity and aligns with recent updates to policy processors.
* feat(train): Integrate preprocessor into training pipeline
* refactor(train): Update preprocessor initialization to include dataset statistics
* refactor(policies): Enhance processor creation and add NaN detection hook
* refactor(train): Update memory pinning logic for mps compatibility
* feat: initial commit phone teleop
* ugly delta control
* use quaternion
* Refactor observation preprocessing to use a modular pipeline system
- Introduced `RobotPipeline` and `ObservationProcessor` for handling observation transformations.
- Updated `preprocess_observation` to maintain backward compatibility while leveraging the new pipeline.
- Added tests for the new processing components and ensured they match the original functionality.
- Removed hardcoded logic in favor of a more flexible, composable architecture.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor observation processing and improve modularity
- Updated `ObservationProcessor` to enhance the modular design for processing observations.
- Cleaned up imports and improved code readability by removing unnecessary lines and comments.
- Ensured backward compatibility while integrating new processing components.
- Added tests to validate the functionality of the updated processing architecture.
* Remove redundant tests for None observation and serialization methods in `test_observation_processor.py` to streamline the test suite and improve maintainability.
* Refactor processing architecture to use RobotProcessor
- Replaced instances of RobotPipeline with RobotProcessor across the codebase for improved modularity and clarity.
- Introduced ProcessorStepRegistry for better management of processing steps.
- Updated relevant documentation and tests to reflect the new processing structure.
- Enhanced the save/load functionality to support the new processor design.
- Added a model card template for RobotProcessor to facilitate sharing and documentation.
* Add RobotProcessor tutorial to documentation
- Introduced a new tutorial on using RobotProcessor for preprocessing robot data.
- Added a section in the table of contents for easy navigation to the new tutorial.
- The tutorial covers key concepts, real-world scenarios, and practical examples for effective use of the RobotProcessor pipeline.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add normalization processor and related components
- Introduced `NormalizationProcessor` to handle both observation normalization and action unnormalization.
- Added `ObservationNormalizer` and `ActionUnnormalizer` classes for specific normalization tasks.
- Updated `__init__.py` to include the new `NormalizationProcessor` in the module exports.
- Enhanced `ObservationProcessor` with registration in the `ProcessorStepRegistry` for better modularity.
- Created `RenameProcessor` for renaming keys in observations, improving flexibility in data processing.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Enhance processing architecture with new components
- Added `RenameProcessor` to facilitate key renaming in observations, improving data handling flexibility.
- Updated `__init__.py` to include `RenameProcessor` in module exports.
- Refactored `NormalizationProcessor` and `ObservationNormalizer` to use `rsplit` for better key handling.
- Introduced comprehensive tests for `NormalizationProcessor` and `RenameProcessor` to ensure functionality and robustness.
* chore (docs): add docstring for processor
* fix (test): test factory
* fix(test): policies
* Update tests/processor/test_observation_processor.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
* chore(test): add suggestion made by copilot regarding numpy test
* fix(test): import issue
* Refactor normalization components and update tests
- Renamed `ObservationNormalizer` to `NormalizerProcessor` and `ActionUnnormalizer` to `UnnormalizerProcessor` for clarity.
- Consolidated normalization logic for both observations and actions into `NormalizerProcessor` and `UnnormalizerProcessor`.
- Updated tests to reflect the new class names and ensure proper functionality of normalization and unnormalization processes.
- Enhanced handling of missing statistics in normalization processes.
* chore (docstrin):Improve docstring for NormalizerProcessor
* feat (device processor): Implement device processor
* chore (batch handling): Enhance processing components with batch conversion utilities
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix(test): linting issue
* chore (output format): improves output format
* chore (type): add typing for multiprocess envs
* feat (overrides): Implement support for loading processors with parameter overrides
- Added the ability to provide non-serializable objects when loading processors from saved configurations using the `overrides` parameter.
- Enhanced error handling for invalid override keys and instantiation errors.
- Updated documentation and examples to illustrate the usage of overrides for both registered and unregistered steps.
- Added comprehensive tests to validate the new functionality and ensure backward compatibility.
* chore(normalization): addressing comments from copilot
* chore(learner): nit comment from copilot
* feat(pipeline): Enhance step_through method to support both tuple and dict inputs
* refactor(pipeline): Simplify observation and padding data handling in batch transitions
* Apply suggestions from code review
Co-authored-by: Simon Alibert <75076266+aliberts@users.noreply.github.com>
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Introduce ComplementaryDataProcessor for handling complementary data in transitions
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Transition from tuple to dictionary format for EnvTransition
- Updated the EnvTransition structure to use a dictionary format instead of a tuple, enhancing readability and maintainability.
- Replaced instances of TransitionIndex with TransitionKey for accessing transition components.
- Adjusted related processing functions and tests to accommodate the new dictionary format, ensuring consistent handling of transitions across the codebase.
* refactor(observation_processor): Improve observation processing by using constants and simplifying pixel handling
- Introduced constants for observation keys to enhance readability.
- Streamlined the handling of the "pixels" key by copying observations first and processing images more clearly.
- Updated the environment state and agent position assignments to use the new constants, improving maintainability.
* feat(pipeline): Add hook unregistration functionality and enhance documentation
- Implemented methods to unregister before, after, and reset hooks in the RobotProcessor class, allowing for more flexible hook management.
- Enhanced documentation to clarify hook execution semantics and the implications of modifying transitions within hooks.
- Added comprehensive tests to verify the correct behavior of hook registration and unregistration, including error handling for non-existent hooks.
* refactor(pipeline): Clarify hook behavior and improve documentation
- Updated the RobotProcessor class to ensure hooks are strictly for observation and do not modify transitions, enhancing clarity and maintainability.
- Refactored hook registration methods to reflect the new behavior, ensuring they accept only functions that do not return modified transitions.
- Enhanced documentation to clearly outline the purpose of hooks and their execution semantics.
- Added tests to verify that hooks are not executed during the step_through method while ensuring they function correctly during the __call__ method.
* feat(pipeline): Add __repr__ method to RobotProcessor for improved readability
- Implemented a __repr__ method in the RobotProcessor class to provide a clear string representation of the processor, including step names and optional parameters like name and seed.
- Added comprehensive tests to validate the __repr__ output for various scenarios, including empty processors, single and multiple steps, custom names, and seed values.
- Ensured that the representation handles long lists of steps with truncation for better readability.
* chore(pipeline): Move _CFG_NAME along other class member
* refactor(pipeline): Utilize get_safe_torch_device for device assignment
- Replaced direct torch.device instantiation with get_safe_torch_device to ensure safe device handling.
- This change enhances code readability and maintains consistency in device management across the RobotProcessor class.
* refactor(pipeline): Enhance state filename generation and profiling method
- Updated state filename generation to use the registry name when available, improving clarity in saved files.
- Modified the profile_steps method to include a warmup_runs parameter, allowing for more controlled performance profiling.
- Ensured consistent conditions during profiling by deep copying transitions for each run, enhancing accuracy in timing results.
* chore(doc): address pip install commant lerobot that not exist yet
* feat(pipeline): Enhance configuration filename handling and state file naming
- Introduced support for custom configuration filenames in the `save_pretrained` method, allowing users to specify a filename instead of the default.
- Improved state file naming to include step indices, preventing conflicts when multiple processors of the same type are saved.
- Added automatic detection for configuration files when loading from a directory, with error handling for multiple files.
- Updated tests to validate new features, including custom filenames and automatic config detection.
* refactor(pipeline): Improve state file naming conventions for clarity and uniqueness
- Enhanced state file naming to include the processor's sanitized name, ensuring uniqueness when multiple processors are saved in the same directory.
- Updated tests to reflect changes in state file naming, verifying that filenames now include the processor name and step indices to prevent conflicts.
- Added a new test to validate state file naming when using multiple processors, ensuring distinct filenames for each processor's state files.
* docs(pipeline): Add clarification for repo name sanitization process
* feat(processors): Introduce processors for various policy types
- Added `make_processor` function to create processor instances for different policy types, including `tdmpc`, `diffusion`, `act`, `vqbet`, `pi0`, `pi0fast`, `sac`, and `reward_classifier`.
- Implemented corresponding processor files for each policy type, encapsulating normalization and unnormalization steps.
- Updated existing policies to remove direct normalization dependencies, enhancing modularity and clarity.
- Enhanced test coverage to validate the integration of new processors with existing policy configurations.
* refactor(learner): Remove normalization from cached image features retrieval
- Simplified the retrieval of observation features by removing the normalization step from the `get_cached_image_features` method calls.
- This change enhances clarity and aligns with the recent updates to policy processors.
* refactor(policies): Remove unnormalization step from action predictions
- Eliminated the unnormalization of actions in both `TDMPCPolicy` and `VQBeTPolicy` classes to streamline action prediction.
- This change improves code clarity and aligns with recent updates to policy processors.
* feat(train): Integrate preprocessor into training pipeline
* refactor(train): Update preprocessor initialization to include dataset statistics
* refactor(policies): Enhance processor creation and add NaN detection hook
* feat(record): Integrate RobotProcessor into recording loop and update policy handling
- Added support for RobotProcessor in the record_loop function to enhance data processing capabilities.
- Updated the logic to reset both policy and processor when provided, ensuring proper state management.
- Modified action prediction to utilize the processor, improving the overall functionality of the recording process.
- Adjusted the save_checkpoint function to include preprocessor state saving, enhancing checkpointing capabilities.
* feat(migration): Add script for migrating policy models with normalization layers
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(migrate): Enhance migration script to create preprocessor and postprocessor for policy models
- Updated the migration script to generate both a preprocessor and a postprocessor, improving the handling of normalization for training and inference.
- Added functionality to convert features to PolicyFeature objects, ensuring compatibility with the new processor architecture.
- Refined the extraction and removal of normalization statistics and layers, streamlining the migration process.
- Improved error handling for missing mandatory configuration fields during model instantiation.
* feat(migrate): Add model card generation and saving to migration script
- Implemented functionality to generate and save a model card for the migrated model, including metadata such as dataset repository ID, license, and tags.
- Enhanced the script to push the model card to the hub if requested, improving model documentation and accessibility.
- Refactored the saving process to ensure the model card is saved locally and uploaded correctly when pushing to the hub.
* feat(processor): Introduce ToBatchProcessor for handling observation batching
- Added ToBatchProcessor to ensure observations have proper batch dimensions for model processing.
- Implemented functionality to add batch dimensions to state and image observations as needed.
- Created comprehensive unit tests to validate the processor's behavior with various tensor dimensions and types.
- Ensured compatibility with existing transition keys and maintained the integrity of non-observation data.
* feat(processors): Add ToBatchProcessor to multiple policy processors
- Integrated ToBatchProcessor into various policy processors to handle observation batching.
- Updated make functions for act, diffusion, pi0, pi0fast, sac, smolvla, tdmpc, and vqbet processors to include the new batching functionality.
- Ensured consistency across all processor implementations for improved data handling.
* refactor(factory): Remove unused imports and NaN detection hook from processor creation
* feat(batch_processor): Enhance ToBatchProcessor to handle action batching
- Updated ToBatchProcessor to add batch dimensions to actions in addition to observations.
- Implemented separate methods for processing observations and actions, improving code readability.
- Added comprehensive unit tests to validate action batching functionality across various tensor dimensions and types.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(factory): Enhance make_processor to support preprocessor and postprocessor configuration
- Introduced ProcessorConfigKwargs TypedDict for better type safety in processor configuration.
- Updated make_processor to accept preprocessor and postprocessor configuration filenames, improving flexibility in processor instantiation.
- Refactored the loading of pretrained processors to utilize the new configuration options.
* refactor(factory): Clean up imports in factory.py
- Removed unused import of IdentityProcessor to streamline the code.
* feat(migrate): Extend load_model_from_hub to include train configuration
- Updated load_model_from_hub to return the train configuration alongside the model state_dict and config.
- Modified main function to handle the additional train configuration when loading models from both the hub and local paths.
- Adjusted dataset_repo_id extraction to utilize the train configuration for improved accuracy.
* refactor(record): Rename processor parameters and update processing logic
- Renamed `processor` to `preprocessor` and added `postprocessor` parameter for clarity.
- Updated the `record_loop` and `predict_action` functions to utilize the new preprocessor and postprocessor, enhancing the processing flow.
- Ensured compatibility with existing functionality while improving code readability.
* feat(batch_processor): Add task field processing to ToBatchProcessor
- Enhanced ToBatchProcessor to wrap string tasks in a list, adding batch dimensions for compatibility with model inference.
- Implemented a new method for processing complementary data, ensuring that task values are correctly handled as either strings or lists of strings.
- Added comprehensive unit tests to validate task processing, including edge cases and in-place mutation of complementary data.
* feat(normalization): Implement IDENTITY mode for normalization and unnormalization
- Enhanced NormalizerProcessor and UnnormalizerProcessor to support IDENTITY mode, allowing features to bypass normalization when specified.
- Updated processing logic to check normalization modes and handle missing statistics gracefully.
- Added comprehensive unit tests to validate IDENTITY mode functionality for both observations and actions, ensuring correct behavior across various scenarios.
- Improved error handling for unsupported normalization modes.
* fix(rebase): remove residual normalization layer:
* refactor(diffusion): remove normalization layer from input processing
* Add debug + calib
* cleanup
* Add pipeline
* fix int
* Add record example
* nit
* Add feature contract to pipelinestep and pipeline
* Add tests
* Add processor tests
* PR feedback
* encorperate pr feedback
* type in doc
* oops
* cleaned up steps and integrated pipeline with feature_contract
* refactor steps and robot to pipeline
* cleanup pipeline
* cleanup code further
* make it run
* feat(processors): Introduce processors for various policy types
- Added `make_processor` function to create processor instances for different policy types, including `tdmpc`, `diffusion`, `act`, `vqbet`, `pi0`, `pi0fast`, `sac`, and `reward_classifier`.
- Implemented corresponding processor files for each policy type, encapsulating normalization and unnormalization steps.
- Updated existing policies to remove direct normalization dependencies, enhancing modularity and clarity.
- Enhanced test coverage to validate the integration of new processors with existing policy configurations.
* refactor(learner): Remove normalization from cached image features retrieval
- Simplified the retrieval of observation features by removing the normalization step from the `get_cached_image_features` method calls.
- This change enhances clarity and aligns with the recent updates to policy processors.
* refactor(policies): Remove unnormalization step from action predictions
- Eliminated the unnormalization of actions in both `TDMPCPolicy` and `VQBeTPolicy` classes to streamline action prediction.
- This change improves code clarity and aligns with recent updates to policy processors.
* feat(train): Integrate preprocessor into training pipeline
* refactor(train): Update preprocessor initialization to include dataset statistics
* refactor(policies): Enhance processor creation and add NaN detection hook
* feat(record): Integrate RobotProcessor into recording loop and update policy handling
- Added support for RobotProcessor in the record_loop function to enhance data processing capabilities.
- Updated the logic to reset both policy and processor when provided, ensuring proper state management.
- Modified action prediction to utilize the processor, improving the overall functionality of the recording process.
- Adjusted the save_checkpoint function to include preprocessor state saving, enhancing checkpointing capabilities.
* feat(migration): Add script for migrating policy models with normalization layers
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(migrate): Enhance migration script to create preprocessor and postprocessor for policy models
- Updated the migration script to generate both a preprocessor and a postprocessor, improving the handling of normalization for training and inference.
- Added functionality to convert features to PolicyFeature objects, ensuring compatibility with the new processor architecture.
- Refined the extraction and removal of normalization statistics and layers, streamlining the migration process.
- Improved error handling for missing mandatory configuration fields during model instantiation.
* feat(migrate): Add model card generation and saving to migration script
- Implemented functionality to generate and save a model card for the migrated model, including metadata such as dataset repository ID, license, and tags.
- Enhanced the script to push the model card to the hub if requested, improving model documentation and accessibility.
- Refactored the saving process to ensure the model card is saved locally and uploaded correctly when pushing to the hub.
* feat(processor): Introduce ToBatchProcessor for handling observation batching
- Added ToBatchProcessor to ensure observations have proper batch dimensions for model processing.
- Implemented functionality to add batch dimensions to state and image observations as needed.
- Created comprehensive unit tests to validate the processor's behavior with various tensor dimensions and types.
- Ensured compatibility with existing transition keys and maintained the integrity of non-observation data.
* feat(processors): Add ToBatchProcessor to multiple policy processors
- Integrated ToBatchProcessor into various policy processors to handle observation batching.
- Updated make functions for act, diffusion, pi0, pi0fast, sac, smolvla, tdmpc, and vqbet processors to include the new batching functionality.
- Ensured consistency across all processor implementations for improved data handling.
* refactor(factory): Remove unused imports and NaN detection hook from processor creation
* feat(batch_processor): Enhance ToBatchProcessor to handle action batching
- Updated ToBatchProcessor to add batch dimensions to actions in addition to observations.
- Implemented separate methods for processing observations and actions, improving code readability.
- Added comprehensive unit tests to validate action batching functionality across various tensor dimensions and types.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(factory): Enhance make_processor to support preprocessor and postprocessor configuration
- Introduced ProcessorConfigKwargs TypedDict for better type safety in processor configuration.
- Updated make_processor to accept preprocessor and postprocessor configuration filenames, improving flexibility in processor instantiation.
- Refactored the loading of pretrained processors to utilize the new configuration options.
* refactor(factory): Clean up imports in factory.py
- Removed unused import of IdentityProcessor to streamline the code.
* feat(migrate): Extend load_model_from_hub to include train configuration
- Updated load_model_from_hub to return the train configuration alongside the model state_dict and config.
- Modified main function to handle the additional train configuration when loading models from both the hub and local paths.
- Adjusted dataset_repo_id extraction to utilize the train configuration for improved accuracy.
* refactor(record): Rename processor parameters and update processing logic
- Renamed `processor` to `preprocessor` and added `postprocessor` parameter for clarity.
- Updated the `record_loop` and `predict_action` functions to utilize the new preprocessor and postprocessor, enhancing the processing flow.
- Ensured compatibility with existing functionality while improving code readability.
* feat(batch_processor): Add task field processing to ToBatchProcessor
- Enhanced ToBatchProcessor to wrap string tasks in a list, adding batch dimensions for compatibility with model inference.
- Implemented a new method for processing complementary data, ensuring that task values are correctly handled as either strings or lists of strings.
- Added comprehensive unit tests to validate task processing, including edge cases and in-place mutation of complementary data.
* feat(normalization): Implement IDENTITY mode for normalization and unnormalization
- Enhanced NormalizerProcessor and UnnormalizerProcessor to support IDENTITY mode, allowing features to bypass normalization when specified.
- Updated processing logic to check normalization modes and handle missing statistics gracefully.
- Added comprehensive unit tests to validate IDENTITY mode functionality for both observations and actions, ensuring correct behavior across various scenarios.
- Improved error handling for unsupported normalization modes.
* fix(rebase): remove residual normalization layer:
* refactor(diffusion): remove normalization layer from input processing
* refactor(normalization): Remove unused state dict transformation methods and streamline imports
- Eliminated the _transform_state_dict_keys and _load_as_safetensor methods from PI0Policy, simplifying the model loading process.
- Cleaned up imports in modeling_pi0.py by removing log_model_loading_keys and init_logging.
- Updated TDMPCPolicy and VQBeTPolicy to handle action removal from batches during offline evaluation.
- Introduced hotswap_stats function in normalize_processor.py to update normalization statistics dynamically, with corresponding tests to ensure functionality.
* refactor(normalization): Clean up imports in normalize_processor.py
* feat(batch_processor): Add feature_contract method to ToBatchProcessor
- Introduced feature_contract method that returns features without modification, maintaining the no-op behavior of the processor.
- This addition enhances the flexibility of the ToBatchProcessor for future feature processing needs.
* fix(dependencies): Update transformers dependency constraint to allow only versions up to 4.52.0
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(tokenizer): Introduce TokenizerProcessor for text tokenization
- Added TokenizerProcessor class to handle tokenization of task strings using Hugging Face's AutoTokenizer.
- Supports both string and list inputs, with customizable parameters for task key, output key, and tokenization settings.
- Implemented comprehensive unit tests to validate functionality, including handling of various input scenarios and integration with RobotProcessor.
- Updated types.py to include LANGUAGE feature type and modified __init__.py to register the new processor.
* feat(language): Enhance language processing in TokenizerProcessor
- Added OBS_LANGUAGE constant to define the observation language key.
- Updated TokenizerProcessor to store tokenized task data in the observation dictionary, ensuring compatibility with the new language feature.
- Introduced Pi0NewLineProcessor to append newlines to tasks for proper tokenization.
- Modified tests to validate the integration of language tokens and attention masks in the observation structure.
* feat(tokenizer): Add padding configuration to TokenizerProcessor
- Introduced `padding_side` parameter to the TokenizerProcessor for customizable padding direction.
- Updated the `make_pi0_processor` function to include the new padding configuration.
- Enhanced unit tests to validate the functionality of the `padding_side` parameter in various scenarios.
* feat(processor): Add state management methods to Pi0NewLineProcessor
* feat(normalization): Track normalization and unnormalization info in complementary data
- Updated NormalizerProcessor and UnnormalizerProcessor to accept additional parameters for tracking normalization modes.
- Enhanced the __call__ methods to store normalization and unnormalization information in the complementary data of transitions.
- Added unit tests to verify the correct tracking of normalization info, including scenarios with missing stats and selective normalization keys.
* feat(factory): Add preprocessor and postprocessor overrides to ProcessorConfigKwargs
- Updated ProcessorConfigKwargs to include optional overrides for preprocessor and postprocessor configurations.
- Enhanced the make_processor function to utilize the new overrides, allowing for more flexible processor initialization.
* feat(processors): Integrate RenameProcessor into various processor configurations
- Added RenameProcessor to the input steps of multiple processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Consolidated normalization features from input and output into a single NormalizerProcessor for improved efficiency.
- Updated the input steps to ensure compatibility with the new RenameProcessor integration.
* Do some todos and cleanup
* change feature_contract to dataset_features
* use one method for conversion pipeline output to add_frame dict and use base processors where possible
* Add back in and use record_loop
* update todo
* rename to_dataset_frame
* feat(smolvla): Refactor language processing and introduce new line processor (#1658)
- Removed the prepare_language method and directly accessed language tokens and masks from the batch using the OBS_LANGUAGE constant.
- Added SmolVLANewLineProcessor to ensure tasks end with a newline, enhancing tokenization compatibility.
- Updated the make_smolvla_processor function to include the new line processor and tokenizer processor for improved input handling.
* feat(processors): Integrate DeviceProcessor into multiple processor configurations
- Added DeviceProcessor to the input and output steps of various processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_pi0fast_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Enhanced the DeviceProcessor class with state management methods and ensured compatibility with existing processor pipelines.
- Introduced unit tests for DeviceProcessor to validate functionality across different scenarios, including CPU and CUDA operations.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* fix reference frame
* refactor(pipeline): Remove to() method for device management
- Eliminated the to() method from RobotProcessor, which was responsible for moving tensor states to specified devices.
- Removed associated unit tests that validated the functionality of the to() method across various scenarios.
- Streamlined the pipeline code by focusing on other device management strategies.
* feat(processor): Enhance DeviceProcessor with float dtype conversion
- Added support for optional float dtype conversion in DeviceProcessor, allowing tensors to be converted to specified floating-point types while preserving non-float types.
- Implemented validation for float dtype input and updated the processor's configuration methods to include float dtype.
- Refactored tensor processing logic to streamline device movement and dtype conversion.
- Introduced comprehensive unit tests to validate the new float dtype functionality across various scenarios.
* update data visualization
* update teleop example
* fix record bugs
* Add replay
* Not code
* feature(pipeline): port tokenizer pipeline for VLA (#1645)
* feat(tokenizer): Introduce TokenizerProcessor for text tokenization
- Added TokenizerProcessor class to handle tokenization of task strings using Hugging Face's AutoTokenizer.
- Supports both string and list inputs, with customizable parameters for task key, output key, and tokenization settings.
- Implemented comprehensive unit tests to validate functionality, including handling of various input scenarios and integration with RobotProcessor.
- Updated types.py to include LANGUAGE feature type and modified __init__.py to register the new processor.
* feat(language): Enhance language processing in TokenizerProcessor
- Added OBS_LANGUAGE constant to define the observation language key.
- Updated TokenizerProcessor to store tokenized task data in the observation dictionary, ensuring compatibility with the new language feature.
- Introduced Pi0NewLineProcessor to append newlines to tasks for proper tokenization.
- Modified tests to validate the integration of language tokens and attention masks in the observation structure.
* feat(tokenizer): Add padding configuration to TokenizerProcessor
- Introduced `padding_side` parameter to the TokenizerProcessor for customizable padding direction.
- Updated the `make_pi0_processor` function to include the new padding configuration.
- Enhanced unit tests to validate the functionality of the `padding_side` parameter in various scenarios.
* feat(processor): Add state management methods to Pi0NewLineProcessor
* feat(normalization): Track normalization and unnormalization info in complementary data
- Updated NormalizerProcessor and UnnormalizerProcessor to accept additional parameters for tracking normalization modes.
- Enhanced the __call__ methods to store normalization and unnormalization information in the complementary data of transitions.
- Added unit tests to verify the correct tracking of normalization info, including scenarios with missing stats and selective normalization keys.
* feat(factory): Add preprocessor and postprocessor overrides to ProcessorConfigKwargs
- Updated ProcessorConfigKwargs to include optional overrides for preprocessor and postprocessor configurations.
- Enhanced the make_processor function to utilize the new overrides, allowing for more flexible processor initialization.
* feat(processors): Integrate RenameProcessor into various processor configurations
- Added RenameProcessor to the input steps of multiple processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Consolidated normalization features from input and output into a single NormalizerProcessor for improved efficiency.
- Updated the input steps to ensure compatibility with the new RenameProcessor integration.
* feat(smolvla): Refactor language processing and introduce new line processor (#1658)
- Removed the prepare_language method and directly accessed language tokens and masks from the batch using the OBS_LANGUAGE constant.
- Added SmolVLANewLineProcessor to ensure tasks end with a newline, enhancing tokenization compatibility.
- Updated the make_smolvla_processor function to include the new line processor and tokenizer processor for improved input handling.
* feture(policies): add device processor (#1659)
* feat(processors): Integrate DeviceProcessor into multiple processor configurations
- Added DeviceProcessor to the input and output steps of various processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_pi0fast_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Enhanced the DeviceProcessor class with state management methods and ensured compatibility with existing processor pipelines.
- Introduced unit tests for DeviceProcessor to validate functionality across different scenarios, including CPU and CUDA operations.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Remove to() method for device management
- Eliminated the to() method from RobotProcessor, which was responsible for moving tensor states to specified devices.
- Removed associated unit tests that validated the functionality of the to() method across various scenarios.
- Streamlined the pipeline code by focusing on other device management strategies.
* feat(processor): Enhance DeviceProcessor with float dtype conversion
- Added support for optional float dtype conversion in DeviceProcessor, allowing tensors to be converted to specified floating-point types while preserving non-float types.
- Implemented validation for float dtype input and updated the processor's configuration methods to include float dtype.
- Refactored tensor processing logic to streamline device movement and dtype conversion.
- Introduced comprehensive unit tests to validate the new float dtype functionality across various scenarios.
* feat(policies): Add new line processors and update module exports
* feat(processor): Enhance batch and device processors to handle index and task_index fields
- Added logic to ToBatchProcessor for unsqueezing 0D tensors for index and task_index fields, ensuring they are processed as 1D tensors.
- Updated DeviceProcessor to process index and task_index fields in complementary data, preserving their tensor types and ensuring non-tensor fields remain unchanged.
- Enhanced unit tests to validate the correct handling of index and task_index fields across various scenarios, including device compatibility and dtype preservation.
* Add eval script
* fix `q_curr` in InverseKinematicsEEToJoints to the IK solution
* feat(processors): Introduce processors for various policy types
- Added `make_processor` function to create processor instances for different policy types, including `tdmpc`, `diffusion`, `act`, `vqbet`, `pi0`, `pi0fast`, `sac`, and `reward_classifier`.
- Implemented corresponding processor files for each policy type, encapsulating normalization and unnormalization steps.
- Updated existing policies to remove direct normalization dependencies, enhancing modularity and clarity.
- Enhanced test coverage to validate the integration of new processors with existing policy configurations.
* refactor(learner): Remove normalization from cached image features retrieval
- Simplified the retrieval of observation features by removing the normalization step from the `get_cached_image_features` method calls.
- This change enhances clarity and aligns with the recent updates to policy processors.
* refactor(policies): Remove unnormalization step from action predictions
- Eliminated the unnormalization of actions in both `TDMPCPolicy` and `VQBeTPolicy` classes to streamline action prediction.
- This change improves code clarity and aligns with recent updates to policy processors.
* feat(train): Integrate preprocessor into training pipeline
* refactor(train): Update preprocessor initialization to include dataset statistics
* refactor(policies): Enhance processor creation and add NaN detection hook
* feat(record): Integrate RobotProcessor into recording loop and update policy handling
- Added support for RobotProcessor in the record_loop function to enhance data processing capabilities.
- Updated the logic to reset both policy and processor when provided, ensuring proper state management.
- Modified action prediction to utilize the processor, improving the overall functionality of the recording process.
- Adjusted the save_checkpoint function to include preprocessor state saving, enhancing checkpointing capabilities.
* feat(migration): Add script for migrating policy models with normalization layers
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(migrate): Enhance migration script to create preprocessor and postprocessor for policy models
- Updated the migration script to generate both a preprocessor and a postprocessor, improving the handling of normalization for training and inference.
- Added functionality to convert features to PolicyFeature objects, ensuring compatibility with the new processor architecture.
- Refined the extraction and removal of normalization statistics and layers, streamlining the migration process.
- Improved error handling for missing mandatory configuration fields during model instantiation.
* feat(migrate): Add model card generation and saving to migration script
- Implemented functionality to generate and save a model card for the migrated model, including metadata such as dataset repository ID, license, and tags.
- Enhanced the script to push the model card to the hub if requested, improving model documentation and accessibility.
- Refactored the saving process to ensure the model card is saved locally and uploaded correctly when pushing to the hub.
* feat(processor): Introduce ToBatchProcessor for handling observation batching
- Added ToBatchProcessor to ensure observations have proper batch dimensions for model processing.
- Implemented functionality to add batch dimensions to state and image observations as needed.
- Created comprehensive unit tests to validate the processor's behavior with various tensor dimensions and types.
- Ensured compatibility with existing transition keys and maintained the integrity of non-observation data.
* feat(processors): Add ToBatchProcessor to multiple policy processors
- Integrated ToBatchProcessor into various policy processors to handle observation batching.
- Updated make functions for act, diffusion, pi0, pi0fast, sac, smolvla, tdmpc, and vqbet processors to include the new batching functionality.
- Ensured consistency across all processor implementations for improved data handling.
* refactor(factory): Remove unused imports and NaN detection hook from processor creation
* feat(batch_processor): Enhance ToBatchProcessor to handle action batching
- Updated ToBatchProcessor to add batch dimensions to actions in addition to observations.
- Implemented separate methods for processing observations and actions, improving code readability.
- Added comprehensive unit tests to validate action batching functionality across various tensor dimensions and types.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(factory): Enhance make_processor to support preprocessor and postprocessor configuration
- Introduced ProcessorConfigKwargs TypedDict for better type safety in processor configuration.
- Updated make_processor to accept preprocessor and postprocessor configuration filenames, improving flexibility in processor instantiation.
- Refactored the loading of pretrained processors to utilize the new configuration options.
* refactor(factory): Clean up imports in factory.py
- Removed unused import of IdentityProcessor to streamline the code.
* feat(migrate): Extend load_model_from_hub to include train configuration
- Updated load_model_from_hub to return the train configuration alongside the model state_dict and config.
- Modified main function to handle the additional train configuration when loading models from both the hub and local paths.
- Adjusted dataset_repo_id extraction to utilize the train configuration for improved accuracy.
* refactor(record): Rename processor parameters and update processing logic
- Renamed `processor` to `preprocessor` and added `postprocessor` parameter for clarity.
- Updated the `record_loop` and `predict_action` functions to utilize the new preprocessor and postprocessor, enhancing the processing flow.
- Ensured compatibility with existing functionality while improving code readability.
* feat(batch_processor): Add task field processing to ToBatchProcessor
- Enhanced ToBatchProcessor to wrap string tasks in a list, adding batch dimensions for compatibility with model inference.
- Implemented a new method for processing complementary data, ensuring that task values are correctly handled as either strings or lists of strings.
- Added comprehensive unit tests to validate task processing, including edge cases and in-place mutation of complementary data.
* feat(normalization): Implement IDENTITY mode for normalization and unnormalization
- Enhanced NormalizerProcessor and UnnormalizerProcessor to support IDENTITY mode, allowing features to bypass normalization when specified.
- Updated processing logic to check normalization modes and handle missing statistics gracefully.
- Added comprehensive unit tests to validate IDENTITY mode functionality for both observations and actions, ensuring correct behavior across various scenarios.
- Improved error handling for unsupported normalization modes.
* fix(rebase): remove residual normalization layer:
* refactor(diffusion): remove normalization layer from input processing
* refactor(normalization): Remove unused state dict transformation methods and streamline imports
- Eliminated the _transform_state_dict_keys and _load_as_safetensor methods from PI0Policy, simplifying the model loading process.
- Cleaned up imports in modeling_pi0.py by removing log_model_loading_keys and init_logging.
- Updated TDMPCPolicy and VQBeTPolicy to handle action removal from batches during offline evaluation.
- Introduced hotswap_stats function in normalize_processor.py to update normalization statistics dynamically, with corresponding tests to ensure functionality.
* refactor(normalization): Clean up imports in normalize_processor.py
* feat(batch_processor): Add feature_contract method to ToBatchProcessor
- Introduced feature_contract method that returns features without modification, maintaining the no-op behavior of the processor.
- This addition enhances the flexibility of the ToBatchProcessor for future feature processing needs.
* fix(dependencies): Update transformers dependency constraint to allow only versions up to 4.52.0
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feature(pipeline): port tokenizer pipeline for VLA (#1645)
* feat(tokenizer): Introduce TokenizerProcessor for text tokenization
- Added TokenizerProcessor class to handle tokenization of task strings using Hugging Face's AutoTokenizer.
- Supports both string and list inputs, with customizable parameters for task key, output key, and tokenization settings.
- Implemented comprehensive unit tests to validate functionality, including handling of various input scenarios and integration with RobotProcessor.
- Updated types.py to include LANGUAGE feature type and modified __init__.py to register the new processor.
* feat(language): Enhance language processing in TokenizerProcessor
- Added OBS_LANGUAGE constant to define the observation language key.
- Updated TokenizerProcessor to store tokenized task data in the observation dictionary, ensuring compatibility with the new language feature.
- Introduced Pi0NewLineProcessor to append newlines to tasks for proper tokenization.
- Modified tests to validate the integration of language tokens and attention masks in the observation structure.
* feat(tokenizer): Add padding configuration to TokenizerProcessor
- Introduced `padding_side` parameter to the TokenizerProcessor for customizable padding direction.
- Updated the `make_pi0_processor` function to include the new padding configuration.
- Enhanced unit tests to validate the functionality of the `padding_side` parameter in various scenarios.
* feat(processor): Add state management methods to Pi0NewLineProcessor
* feat(normalization): Track normalization and unnormalization info in complementary data
- Updated NormalizerProcessor and UnnormalizerProcessor to accept additional parameters for tracking normalization modes.
- Enhanced the __call__ methods to store normalization and unnormalization information in the complementary data of transitions.
- Added unit tests to verify the correct tracking of normalization info, including scenarios with missing stats and selective normalization keys.
* feat(factory): Add preprocessor and postprocessor overrides to ProcessorConfigKwargs
- Updated ProcessorConfigKwargs to include optional overrides for preprocessor and postprocessor configurations.
- Enhanced the make_processor function to utilize the new overrides, allowing for more flexible processor initialization.
* feat(processors): Integrate RenameProcessor into various processor configurations
- Added RenameProcessor to the input steps of multiple processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Consolidated normalization features from input and output into a single NormalizerProcessor for improved efficiency.
- Updated the input steps to ensure compatibility with the new RenameProcessor integration.
* feat(smolvla): Refactor language processing and introduce new line processor (#1658)
- Removed the prepare_language method and directly accessed language tokens and masks from the batch using the OBS_LANGUAGE constant.
- Added SmolVLANewLineProcessor to ensure tasks end with a newline, enhancing tokenization compatibility.
- Updated the make_smolvla_processor function to include the new line processor and tokenizer processor for improved input handling.
* feture(policies): add device processor (#1659)
* feat(processors): Integrate DeviceProcessor into multiple processor configurations
- Added DeviceProcessor to the input and output steps of various processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_pi0fast_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Enhanced the DeviceProcessor class with state management methods and ensured compatibility with existing processor pipelines.
- Introduced unit tests for DeviceProcessor to validate functionality across different scenarios, including CPU and CUDA operations.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Remove to() method for device management
- Eliminated the to() method from RobotProcessor, which was responsible for moving tensor states to specified devices.
- Removed associated unit tests that validated the functionality of the to() method across various scenarios.
- Streamlined the pipeline code by focusing on other device management strategies.
* feat(processor): Enhance DeviceProcessor with float dtype conversion
- Added support for optional float dtype conversion in DeviceProcessor, allowing tensors to be converted to specified floating-point types while preserving non-float types.
- Implemented validation for float dtype input and updated the processor's configuration methods to include float dtype.
- Refactored tensor processing logic to streamline device movement and dtype conversion.
- Introduced comprehensive unit tests to validate the new float dtype functionality across various scenarios.
* feat(policies): Add new line processors and update module exports
* feat(processor): Enhance batch and device processors to handle index and task_index fields
- Added logic to ToBatchProcessor for unsqueezing 0D tensors for index and task_index fields, ensuring they are processed as 1D tensors.
- Updated DeviceProcessor to process index and task_index fields in complementary data, preserving their tensor types and ensuring non-tensor fields remain unchanged.
- Enhanced unit tests to validate the correct handling of index and task_index fields across various scenarios, including device compatibility and dtype preservation.
* refactor(processors): Standardize processor naming conventions
- Updated processor names across various files to use a consistent "robot_preprocessor" and "robot_postprocessor" format.
- Modified the make_processor functions in factory, act, diffusion, pi0, pi0fast, sac, smolvla, tdmpc, and vqbet to reflect the new naming scheme.
- Enhanced the pipeline configuration to align with the updated processor names, improving clarity and maintainability.
* refactor(factory): Update processor configuration and type hints
- Changed return type of get_policy_class to type[PreTrainedPolicy] for improved type safety.
- Enhanced make_processor function to utilize dataset_stats in processor creation for better flexibility.
- Updated ProcessorConfigKwargs to include dataset_stats, allowing for more comprehensive processor configurations.
- Streamlined processor initialization by removing unnecessary kwargs and ensuring clarity in processor type handling.
* Fix eval and android gripper
* add some tests
* refactor(factory, pi0fast): Update processor function names and parameters
- Renamed make_pi0_processor to make_pi0fast_processor for clarity and consistency.
- Updated parameter names in the factory's make_processor function to use pretrained_model_name_or_path instead of source, enhancing readability and alignment with naming conventions.
* fix(train.py) push postprocessor with preprocessor
- Add preprocesser policy overrides for device and rename_map
- Add rename_map to DatasetRecordConfig (record.py)
* Cleanup pr
* fix more git diff pr issues
* add path as type in save_pretrained
* small nit
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* rename test file
* fix: make dataset_features/feature_contract is optional
* fix tests
* Encorperate pr feedback
* clean up record.py
* add ascii art, fix normal record
* remove merge issues
* fix merge
* remove features
* Add feedback PR
* fix last 4 tests
* remove features check
* rename to transform_features
* add transform_features
* fix lekiwi eval and update eval api example
---------
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
Signed-off-by: Pepijn <138571049+pkooij@users.noreply.github.com>
Co-authored-by: Adil Zouitine <adilzouitinegm@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Simon Alibert <75076266+aliberts@users.noreply.github.com>
Co-authored-by: Michel Aractingi <michel.aractingi@huggingface.co>
2025-08-07 16:13:34 +02:00
|
|
|
|
Apply ALL steps in order. Only if a step has a features method, it will be called.
|
|
|
|
|
|
We aggregate the dataset features of all steps.
|
2025-07-31 16:29:48 +02:00
|
|
|
|
"""
|
|
|
|
|
|
features: dict[str, PolicyFeature] = deepcopy(initial_features)
|
|
|
|
|
|
|
|
|
|
|
|
for _, step in enumerate(self.steps):
|
Integrate pipeline and add phone teleop (#1681)
* Add normalization processor and related components
- Introduced `NormalizationProcessor` to handle both observation normalization and action unnormalization.
- Added `ObservationNormalizer` and `ActionUnnormalizer` classes for specific normalization tasks.
- Updated `__init__.py` to include the new `NormalizationProcessor` in the module exports.
- Enhanced `ObservationProcessor` with registration in the `ProcessorStepRegistry` for better modularity.
- Created `RenameProcessor` for renaming keys in observations, improving flexibility in data processing.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Enhance processing architecture with new components
- Added `RenameProcessor` to facilitate key renaming in observations, improving data handling flexibility.
- Updated `__init__.py` to include `RenameProcessor` in module exports.
- Refactored `NormalizationProcessor` and `ObservationNormalizer` to use `rsplit` for better key handling.
- Introduced comprehensive tests for `NormalizationProcessor` and `RenameProcessor` to ensure functionality and robustness.
* chore (docs): add docstring for processor
* fix (test): test factory
* fix(test): policies
* Update tests/processor/test_observation_processor.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
* chore(test): add suggestion made by copilot regarding numpy test
* fix(test): import issue
* Refactor normalization components and update tests
- Renamed `ObservationNormalizer` to `NormalizerProcessor` and `ActionUnnormalizer` to `UnnormalizerProcessor` for clarity.
- Consolidated normalization logic for both observations and actions into `NormalizerProcessor` and `UnnormalizerProcessor`.
- Updated tests to reflect the new class names and ensure proper functionality of normalization and unnormalization processes.
- Enhanced handling of missing statistics in normalization processes.
* chore (docstrin):Improve docstring for NormalizerProcessor
* feat (device processor): Implement device processor
* chore (batch handling): Enhance processing components with batch conversion utilities
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix(test): linting issue
* chore (output format): improves output format
* chore (type): add typing for multiprocess envs
* feat (overrides): Implement support for loading processors with parameter overrides
- Added the ability to provide non-serializable objects when loading processors from saved configurations using the `overrides` parameter.
- Enhanced error handling for invalid override keys and instantiation errors.
- Updated documentation and examples to illustrate the usage of overrides for both registered and unregistered steps.
- Added comprehensive tests to validate the new functionality and ensure backward compatibility.
* chore(normalization): addressing comments from copilot
* chore(learner): nit comment from copilot
* feat(pipeline): Enhance step_through method to support both tuple and dict inputs
* refactor(pipeline): Simplify observation and padding data handling in batch transitions
* Apply suggestions from code review
Co-authored-by: Simon Alibert <75076266+aliberts@users.noreply.github.com>
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Introduce ComplementaryDataProcessor for handling complementary data in transitions
* fix(ci): temporary fix on dataset deps version
* feat(processors): Introduce processors for various policy types
- Added `make_processor` function to create processor instances for different policy types, including `tdmpc`, `diffusion`, `act`, `vqbet`, `pi0`, `pi0fast`, `sac`, and `reward_classifier`.
- Implemented corresponding processor files for each policy type, encapsulating normalization and unnormalization steps.
- Updated existing policies to remove direct normalization dependencies, enhancing modularity and clarity.
- Enhanced test coverage to validate the integration of new processors with existing policy configurations.
* refactor(learner): Remove normalization from cached image features retrieval
- Simplified the retrieval of observation features by removing the normalization step from the `get_cached_image_features` method calls.
- This change enhances clarity and aligns with the recent updates to policy processors.
* refactor(policies): Remove unnormalization step from action predictions
- Eliminated the unnormalization of actions in both `TDMPCPolicy` and `VQBeTPolicy` classes to streamline action prediction.
- This change improves code clarity and aligns with recent updates to policy processors.
* feat(train): Integrate preprocessor into training pipeline
* refactor(train): Update preprocessor initialization to include dataset statistics
* refactor(policies): Enhance processor creation and add NaN detection hook
* refactor(train): Update memory pinning logic for mps compatibility
* feat: initial commit phone teleop
* ugly delta control
* use quaternion
* Refactor observation preprocessing to use a modular pipeline system
- Introduced `RobotPipeline` and `ObservationProcessor` for handling observation transformations.
- Updated `preprocess_observation` to maintain backward compatibility while leveraging the new pipeline.
- Added tests for the new processing components and ensured they match the original functionality.
- Removed hardcoded logic in favor of a more flexible, composable architecture.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor observation processing and improve modularity
- Updated `ObservationProcessor` to enhance the modular design for processing observations.
- Cleaned up imports and improved code readability by removing unnecessary lines and comments.
- Ensured backward compatibility while integrating new processing components.
- Added tests to validate the functionality of the updated processing architecture.
* Remove redundant tests for None observation and serialization methods in `test_observation_processor.py` to streamline the test suite and improve maintainability.
* Refactor processing architecture to use RobotProcessor
- Replaced instances of RobotPipeline with RobotProcessor across the codebase for improved modularity and clarity.
- Introduced ProcessorStepRegistry for better management of processing steps.
- Updated relevant documentation and tests to reflect the new processing structure.
- Enhanced the save/load functionality to support the new processor design.
- Added a model card template for RobotProcessor to facilitate sharing and documentation.
* Add RobotProcessor tutorial to documentation
- Introduced a new tutorial on using RobotProcessor for preprocessing robot data.
- Added a section in the table of contents for easy navigation to the new tutorial.
- The tutorial covers key concepts, real-world scenarios, and practical examples for effective use of the RobotProcessor pipeline.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add normalization processor and related components
- Introduced `NormalizationProcessor` to handle both observation normalization and action unnormalization.
- Added `ObservationNormalizer` and `ActionUnnormalizer` classes for specific normalization tasks.
- Updated `__init__.py` to include the new `NormalizationProcessor` in the module exports.
- Enhanced `ObservationProcessor` with registration in the `ProcessorStepRegistry` for better modularity.
- Created `RenameProcessor` for renaming keys in observations, improving flexibility in data processing.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Enhance processing architecture with new components
- Added `RenameProcessor` to facilitate key renaming in observations, improving data handling flexibility.
- Updated `__init__.py` to include `RenameProcessor` in module exports.
- Refactored `NormalizationProcessor` and `ObservationNormalizer` to use `rsplit` for better key handling.
- Introduced comprehensive tests for `NormalizationProcessor` and `RenameProcessor` to ensure functionality and robustness.
* chore (docs): add docstring for processor
* fix (test): test factory
* fix(test): policies
* Update tests/processor/test_observation_processor.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
* chore(test): add suggestion made by copilot regarding numpy test
* fix(test): import issue
* Refactor normalization components and update tests
- Renamed `ObservationNormalizer` to `NormalizerProcessor` and `ActionUnnormalizer` to `UnnormalizerProcessor` for clarity.
- Consolidated normalization logic for both observations and actions into `NormalizerProcessor` and `UnnormalizerProcessor`.
- Updated tests to reflect the new class names and ensure proper functionality of normalization and unnormalization processes.
- Enhanced handling of missing statistics in normalization processes.
* chore (docstrin):Improve docstring for NormalizerProcessor
* feat (device processor): Implement device processor
* chore (batch handling): Enhance processing components with batch conversion utilities
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix(test): linting issue
* chore (output format): improves output format
* chore (type): add typing for multiprocess envs
* feat (overrides): Implement support for loading processors with parameter overrides
- Added the ability to provide non-serializable objects when loading processors from saved configurations using the `overrides` parameter.
- Enhanced error handling for invalid override keys and instantiation errors.
- Updated documentation and examples to illustrate the usage of overrides for both registered and unregistered steps.
- Added comprehensive tests to validate the new functionality and ensure backward compatibility.
* chore(normalization): addressing comments from copilot
* chore(learner): nit comment from copilot
* feat(pipeline): Enhance step_through method to support both tuple and dict inputs
* refactor(pipeline): Simplify observation and padding data handling in batch transitions
* Apply suggestions from code review
Co-authored-by: Simon Alibert <75076266+aliberts@users.noreply.github.com>
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Introduce ComplementaryDataProcessor for handling complementary data in transitions
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Transition from tuple to dictionary format for EnvTransition
- Updated the EnvTransition structure to use a dictionary format instead of a tuple, enhancing readability and maintainability.
- Replaced instances of TransitionIndex with TransitionKey for accessing transition components.
- Adjusted related processing functions and tests to accommodate the new dictionary format, ensuring consistent handling of transitions across the codebase.
* refactor(observation_processor): Improve observation processing by using constants and simplifying pixel handling
- Introduced constants for observation keys to enhance readability.
- Streamlined the handling of the "pixels" key by copying observations first and processing images more clearly.
- Updated the environment state and agent position assignments to use the new constants, improving maintainability.
* feat(pipeline): Add hook unregistration functionality and enhance documentation
- Implemented methods to unregister before, after, and reset hooks in the RobotProcessor class, allowing for more flexible hook management.
- Enhanced documentation to clarify hook execution semantics and the implications of modifying transitions within hooks.
- Added comprehensive tests to verify the correct behavior of hook registration and unregistration, including error handling for non-existent hooks.
* refactor(pipeline): Clarify hook behavior and improve documentation
- Updated the RobotProcessor class to ensure hooks are strictly for observation and do not modify transitions, enhancing clarity and maintainability.
- Refactored hook registration methods to reflect the new behavior, ensuring they accept only functions that do not return modified transitions.
- Enhanced documentation to clearly outline the purpose of hooks and their execution semantics.
- Added tests to verify that hooks are not executed during the step_through method while ensuring they function correctly during the __call__ method.
* feat(pipeline): Add __repr__ method to RobotProcessor for improved readability
- Implemented a __repr__ method in the RobotProcessor class to provide a clear string representation of the processor, including step names and optional parameters like name and seed.
- Added comprehensive tests to validate the __repr__ output for various scenarios, including empty processors, single and multiple steps, custom names, and seed values.
- Ensured that the representation handles long lists of steps with truncation for better readability.
* chore(pipeline): Move _CFG_NAME along other class member
* refactor(pipeline): Utilize get_safe_torch_device for device assignment
- Replaced direct torch.device instantiation with get_safe_torch_device to ensure safe device handling.
- This change enhances code readability and maintains consistency in device management across the RobotProcessor class.
* refactor(pipeline): Enhance state filename generation and profiling method
- Updated state filename generation to use the registry name when available, improving clarity in saved files.
- Modified the profile_steps method to include a warmup_runs parameter, allowing for more controlled performance profiling.
- Ensured consistent conditions during profiling by deep copying transitions for each run, enhancing accuracy in timing results.
* chore(doc): address pip install commant lerobot that not exist yet
* feat(pipeline): Enhance configuration filename handling and state file naming
- Introduced support for custom configuration filenames in the `save_pretrained` method, allowing users to specify a filename instead of the default.
- Improved state file naming to include step indices, preventing conflicts when multiple processors of the same type are saved.
- Added automatic detection for configuration files when loading from a directory, with error handling for multiple files.
- Updated tests to validate new features, including custom filenames and automatic config detection.
* refactor(pipeline): Improve state file naming conventions for clarity and uniqueness
- Enhanced state file naming to include the processor's sanitized name, ensuring uniqueness when multiple processors are saved in the same directory.
- Updated tests to reflect changes in state file naming, verifying that filenames now include the processor name and step indices to prevent conflicts.
- Added a new test to validate state file naming when using multiple processors, ensuring distinct filenames for each processor's state files.
* docs(pipeline): Add clarification for repo name sanitization process
* feat(processors): Introduce processors for various policy types
- Added `make_processor` function to create processor instances for different policy types, including `tdmpc`, `diffusion`, `act`, `vqbet`, `pi0`, `pi0fast`, `sac`, and `reward_classifier`.
- Implemented corresponding processor files for each policy type, encapsulating normalization and unnormalization steps.
- Updated existing policies to remove direct normalization dependencies, enhancing modularity and clarity.
- Enhanced test coverage to validate the integration of new processors with existing policy configurations.
* refactor(learner): Remove normalization from cached image features retrieval
- Simplified the retrieval of observation features by removing the normalization step from the `get_cached_image_features` method calls.
- This change enhances clarity and aligns with the recent updates to policy processors.
* refactor(policies): Remove unnormalization step from action predictions
- Eliminated the unnormalization of actions in both `TDMPCPolicy` and `VQBeTPolicy` classes to streamline action prediction.
- This change improves code clarity and aligns with recent updates to policy processors.
* feat(train): Integrate preprocessor into training pipeline
* refactor(train): Update preprocessor initialization to include dataset statistics
* refactor(policies): Enhance processor creation and add NaN detection hook
* feat(record): Integrate RobotProcessor into recording loop and update policy handling
- Added support for RobotProcessor in the record_loop function to enhance data processing capabilities.
- Updated the logic to reset both policy and processor when provided, ensuring proper state management.
- Modified action prediction to utilize the processor, improving the overall functionality of the recording process.
- Adjusted the save_checkpoint function to include preprocessor state saving, enhancing checkpointing capabilities.
* feat(migration): Add script for migrating policy models with normalization layers
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(migrate): Enhance migration script to create preprocessor and postprocessor for policy models
- Updated the migration script to generate both a preprocessor and a postprocessor, improving the handling of normalization for training and inference.
- Added functionality to convert features to PolicyFeature objects, ensuring compatibility with the new processor architecture.
- Refined the extraction and removal of normalization statistics and layers, streamlining the migration process.
- Improved error handling for missing mandatory configuration fields during model instantiation.
* feat(migrate): Add model card generation and saving to migration script
- Implemented functionality to generate and save a model card for the migrated model, including metadata such as dataset repository ID, license, and tags.
- Enhanced the script to push the model card to the hub if requested, improving model documentation and accessibility.
- Refactored the saving process to ensure the model card is saved locally and uploaded correctly when pushing to the hub.
* feat(processor): Introduce ToBatchProcessor for handling observation batching
- Added ToBatchProcessor to ensure observations have proper batch dimensions for model processing.
- Implemented functionality to add batch dimensions to state and image observations as needed.
- Created comprehensive unit tests to validate the processor's behavior with various tensor dimensions and types.
- Ensured compatibility with existing transition keys and maintained the integrity of non-observation data.
* feat(processors): Add ToBatchProcessor to multiple policy processors
- Integrated ToBatchProcessor into various policy processors to handle observation batching.
- Updated make functions for act, diffusion, pi0, pi0fast, sac, smolvla, tdmpc, and vqbet processors to include the new batching functionality.
- Ensured consistency across all processor implementations for improved data handling.
* refactor(factory): Remove unused imports and NaN detection hook from processor creation
* feat(batch_processor): Enhance ToBatchProcessor to handle action batching
- Updated ToBatchProcessor to add batch dimensions to actions in addition to observations.
- Implemented separate methods for processing observations and actions, improving code readability.
- Added comprehensive unit tests to validate action batching functionality across various tensor dimensions and types.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(factory): Enhance make_processor to support preprocessor and postprocessor configuration
- Introduced ProcessorConfigKwargs TypedDict for better type safety in processor configuration.
- Updated make_processor to accept preprocessor and postprocessor configuration filenames, improving flexibility in processor instantiation.
- Refactored the loading of pretrained processors to utilize the new configuration options.
* refactor(factory): Clean up imports in factory.py
- Removed unused import of IdentityProcessor to streamline the code.
* feat(migrate): Extend load_model_from_hub to include train configuration
- Updated load_model_from_hub to return the train configuration alongside the model state_dict and config.
- Modified main function to handle the additional train configuration when loading models from both the hub and local paths.
- Adjusted dataset_repo_id extraction to utilize the train configuration for improved accuracy.
* refactor(record): Rename processor parameters and update processing logic
- Renamed `processor` to `preprocessor` and added `postprocessor` parameter for clarity.
- Updated the `record_loop` and `predict_action` functions to utilize the new preprocessor and postprocessor, enhancing the processing flow.
- Ensured compatibility with existing functionality while improving code readability.
* feat(batch_processor): Add task field processing to ToBatchProcessor
- Enhanced ToBatchProcessor to wrap string tasks in a list, adding batch dimensions for compatibility with model inference.
- Implemented a new method for processing complementary data, ensuring that task values are correctly handled as either strings or lists of strings.
- Added comprehensive unit tests to validate task processing, including edge cases and in-place mutation of complementary data.
* feat(normalization): Implement IDENTITY mode for normalization and unnormalization
- Enhanced NormalizerProcessor and UnnormalizerProcessor to support IDENTITY mode, allowing features to bypass normalization when specified.
- Updated processing logic to check normalization modes and handle missing statistics gracefully.
- Added comprehensive unit tests to validate IDENTITY mode functionality for both observations and actions, ensuring correct behavior across various scenarios.
- Improved error handling for unsupported normalization modes.
* fix(rebase): remove residual normalization layer:
* refactor(diffusion): remove normalization layer from input processing
* Add debug + calib
* cleanup
* Add pipeline
* fix int
* Add record example
* nit
* Add feature contract to pipelinestep and pipeline
* Add tests
* Add processor tests
* PR feedback
* encorperate pr feedback
* type in doc
* oops
* cleaned up steps and integrated pipeline with feature_contract
* refactor steps and robot to pipeline
* cleanup pipeline
* cleanup code further
* make it run
* feat(processors): Introduce processors for various policy types
- Added `make_processor` function to create processor instances for different policy types, including `tdmpc`, `diffusion`, `act`, `vqbet`, `pi0`, `pi0fast`, `sac`, and `reward_classifier`.
- Implemented corresponding processor files for each policy type, encapsulating normalization and unnormalization steps.
- Updated existing policies to remove direct normalization dependencies, enhancing modularity and clarity.
- Enhanced test coverage to validate the integration of new processors with existing policy configurations.
* refactor(learner): Remove normalization from cached image features retrieval
- Simplified the retrieval of observation features by removing the normalization step from the `get_cached_image_features` method calls.
- This change enhances clarity and aligns with the recent updates to policy processors.
* refactor(policies): Remove unnormalization step from action predictions
- Eliminated the unnormalization of actions in both `TDMPCPolicy` and `VQBeTPolicy` classes to streamline action prediction.
- This change improves code clarity and aligns with recent updates to policy processors.
* feat(train): Integrate preprocessor into training pipeline
* refactor(train): Update preprocessor initialization to include dataset statistics
* refactor(policies): Enhance processor creation and add NaN detection hook
* feat(record): Integrate RobotProcessor into recording loop and update policy handling
- Added support for RobotProcessor in the record_loop function to enhance data processing capabilities.
- Updated the logic to reset both policy and processor when provided, ensuring proper state management.
- Modified action prediction to utilize the processor, improving the overall functionality of the recording process.
- Adjusted the save_checkpoint function to include preprocessor state saving, enhancing checkpointing capabilities.
* feat(migration): Add script for migrating policy models with normalization layers
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(migrate): Enhance migration script to create preprocessor and postprocessor for policy models
- Updated the migration script to generate both a preprocessor and a postprocessor, improving the handling of normalization for training and inference.
- Added functionality to convert features to PolicyFeature objects, ensuring compatibility with the new processor architecture.
- Refined the extraction and removal of normalization statistics and layers, streamlining the migration process.
- Improved error handling for missing mandatory configuration fields during model instantiation.
* feat(migrate): Add model card generation and saving to migration script
- Implemented functionality to generate and save a model card for the migrated model, including metadata such as dataset repository ID, license, and tags.
- Enhanced the script to push the model card to the hub if requested, improving model documentation and accessibility.
- Refactored the saving process to ensure the model card is saved locally and uploaded correctly when pushing to the hub.
* feat(processor): Introduce ToBatchProcessor for handling observation batching
- Added ToBatchProcessor to ensure observations have proper batch dimensions for model processing.
- Implemented functionality to add batch dimensions to state and image observations as needed.
- Created comprehensive unit tests to validate the processor's behavior with various tensor dimensions and types.
- Ensured compatibility with existing transition keys and maintained the integrity of non-observation data.
* feat(processors): Add ToBatchProcessor to multiple policy processors
- Integrated ToBatchProcessor into various policy processors to handle observation batching.
- Updated make functions for act, diffusion, pi0, pi0fast, sac, smolvla, tdmpc, and vqbet processors to include the new batching functionality.
- Ensured consistency across all processor implementations for improved data handling.
* refactor(factory): Remove unused imports and NaN detection hook from processor creation
* feat(batch_processor): Enhance ToBatchProcessor to handle action batching
- Updated ToBatchProcessor to add batch dimensions to actions in addition to observations.
- Implemented separate methods for processing observations and actions, improving code readability.
- Added comprehensive unit tests to validate action batching functionality across various tensor dimensions and types.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(factory): Enhance make_processor to support preprocessor and postprocessor configuration
- Introduced ProcessorConfigKwargs TypedDict for better type safety in processor configuration.
- Updated make_processor to accept preprocessor and postprocessor configuration filenames, improving flexibility in processor instantiation.
- Refactored the loading of pretrained processors to utilize the new configuration options.
* refactor(factory): Clean up imports in factory.py
- Removed unused import of IdentityProcessor to streamline the code.
* feat(migrate): Extend load_model_from_hub to include train configuration
- Updated load_model_from_hub to return the train configuration alongside the model state_dict and config.
- Modified main function to handle the additional train configuration when loading models from both the hub and local paths.
- Adjusted dataset_repo_id extraction to utilize the train configuration for improved accuracy.
* refactor(record): Rename processor parameters and update processing logic
- Renamed `processor` to `preprocessor` and added `postprocessor` parameter for clarity.
- Updated the `record_loop` and `predict_action` functions to utilize the new preprocessor and postprocessor, enhancing the processing flow.
- Ensured compatibility with existing functionality while improving code readability.
* feat(batch_processor): Add task field processing to ToBatchProcessor
- Enhanced ToBatchProcessor to wrap string tasks in a list, adding batch dimensions for compatibility with model inference.
- Implemented a new method for processing complementary data, ensuring that task values are correctly handled as either strings or lists of strings.
- Added comprehensive unit tests to validate task processing, including edge cases and in-place mutation of complementary data.
* feat(normalization): Implement IDENTITY mode for normalization and unnormalization
- Enhanced NormalizerProcessor and UnnormalizerProcessor to support IDENTITY mode, allowing features to bypass normalization when specified.
- Updated processing logic to check normalization modes and handle missing statistics gracefully.
- Added comprehensive unit tests to validate IDENTITY mode functionality for both observations and actions, ensuring correct behavior across various scenarios.
- Improved error handling for unsupported normalization modes.
* fix(rebase): remove residual normalization layer:
* refactor(diffusion): remove normalization layer from input processing
* refactor(normalization): Remove unused state dict transformation methods and streamline imports
- Eliminated the _transform_state_dict_keys and _load_as_safetensor methods from PI0Policy, simplifying the model loading process.
- Cleaned up imports in modeling_pi0.py by removing log_model_loading_keys and init_logging.
- Updated TDMPCPolicy and VQBeTPolicy to handle action removal from batches during offline evaluation.
- Introduced hotswap_stats function in normalize_processor.py to update normalization statistics dynamically, with corresponding tests to ensure functionality.
* refactor(normalization): Clean up imports in normalize_processor.py
* feat(batch_processor): Add feature_contract method to ToBatchProcessor
- Introduced feature_contract method that returns features without modification, maintaining the no-op behavior of the processor.
- This addition enhances the flexibility of the ToBatchProcessor for future feature processing needs.
* fix(dependencies): Update transformers dependency constraint to allow only versions up to 4.52.0
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(tokenizer): Introduce TokenizerProcessor for text tokenization
- Added TokenizerProcessor class to handle tokenization of task strings using Hugging Face's AutoTokenizer.
- Supports both string and list inputs, with customizable parameters for task key, output key, and tokenization settings.
- Implemented comprehensive unit tests to validate functionality, including handling of various input scenarios and integration with RobotProcessor.
- Updated types.py to include LANGUAGE feature type and modified __init__.py to register the new processor.
* feat(language): Enhance language processing in TokenizerProcessor
- Added OBS_LANGUAGE constant to define the observation language key.
- Updated TokenizerProcessor to store tokenized task data in the observation dictionary, ensuring compatibility with the new language feature.
- Introduced Pi0NewLineProcessor to append newlines to tasks for proper tokenization.
- Modified tests to validate the integration of language tokens and attention masks in the observation structure.
* feat(tokenizer): Add padding configuration to TokenizerProcessor
- Introduced `padding_side` parameter to the TokenizerProcessor for customizable padding direction.
- Updated the `make_pi0_processor` function to include the new padding configuration.
- Enhanced unit tests to validate the functionality of the `padding_side` parameter in various scenarios.
* feat(processor): Add state management methods to Pi0NewLineProcessor
* feat(normalization): Track normalization and unnormalization info in complementary data
- Updated NormalizerProcessor and UnnormalizerProcessor to accept additional parameters for tracking normalization modes.
- Enhanced the __call__ methods to store normalization and unnormalization information in the complementary data of transitions.
- Added unit tests to verify the correct tracking of normalization info, including scenarios with missing stats and selective normalization keys.
* feat(factory): Add preprocessor and postprocessor overrides to ProcessorConfigKwargs
- Updated ProcessorConfigKwargs to include optional overrides for preprocessor and postprocessor configurations.
- Enhanced the make_processor function to utilize the new overrides, allowing for more flexible processor initialization.
* feat(processors): Integrate RenameProcessor into various processor configurations
- Added RenameProcessor to the input steps of multiple processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Consolidated normalization features from input and output into a single NormalizerProcessor for improved efficiency.
- Updated the input steps to ensure compatibility with the new RenameProcessor integration.
* Do some todos and cleanup
* change feature_contract to dataset_features
* use one method for conversion pipeline output to add_frame dict and use base processors where possible
* Add back in and use record_loop
* update todo
* rename to_dataset_frame
* feat(smolvla): Refactor language processing and introduce new line processor (#1658)
- Removed the prepare_language method and directly accessed language tokens and masks from the batch using the OBS_LANGUAGE constant.
- Added SmolVLANewLineProcessor to ensure tasks end with a newline, enhancing tokenization compatibility.
- Updated the make_smolvla_processor function to include the new line processor and tokenizer processor for improved input handling.
* feat(processors): Integrate DeviceProcessor into multiple processor configurations
- Added DeviceProcessor to the input and output steps of various processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_pi0fast_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Enhanced the DeviceProcessor class with state management methods and ensured compatibility with existing processor pipelines.
- Introduced unit tests for DeviceProcessor to validate functionality across different scenarios, including CPU and CUDA operations.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* fix reference frame
* refactor(pipeline): Remove to() method for device management
- Eliminated the to() method from RobotProcessor, which was responsible for moving tensor states to specified devices.
- Removed associated unit tests that validated the functionality of the to() method across various scenarios.
- Streamlined the pipeline code by focusing on other device management strategies.
* feat(processor): Enhance DeviceProcessor with float dtype conversion
- Added support for optional float dtype conversion in DeviceProcessor, allowing tensors to be converted to specified floating-point types while preserving non-float types.
- Implemented validation for float dtype input and updated the processor's configuration methods to include float dtype.
- Refactored tensor processing logic to streamline device movement and dtype conversion.
- Introduced comprehensive unit tests to validate the new float dtype functionality across various scenarios.
* update data visualization
* update teleop example
* fix record bugs
* Add replay
* Not code
* feature(pipeline): port tokenizer pipeline for VLA (#1645)
* feat(tokenizer): Introduce TokenizerProcessor for text tokenization
- Added TokenizerProcessor class to handle tokenization of task strings using Hugging Face's AutoTokenizer.
- Supports both string and list inputs, with customizable parameters for task key, output key, and tokenization settings.
- Implemented comprehensive unit tests to validate functionality, including handling of various input scenarios and integration with RobotProcessor.
- Updated types.py to include LANGUAGE feature type and modified __init__.py to register the new processor.
* feat(language): Enhance language processing in TokenizerProcessor
- Added OBS_LANGUAGE constant to define the observation language key.
- Updated TokenizerProcessor to store tokenized task data in the observation dictionary, ensuring compatibility with the new language feature.
- Introduced Pi0NewLineProcessor to append newlines to tasks for proper tokenization.
- Modified tests to validate the integration of language tokens and attention masks in the observation structure.
* feat(tokenizer): Add padding configuration to TokenizerProcessor
- Introduced `padding_side` parameter to the TokenizerProcessor for customizable padding direction.
- Updated the `make_pi0_processor` function to include the new padding configuration.
- Enhanced unit tests to validate the functionality of the `padding_side` parameter in various scenarios.
* feat(processor): Add state management methods to Pi0NewLineProcessor
* feat(normalization): Track normalization and unnormalization info in complementary data
- Updated NormalizerProcessor and UnnormalizerProcessor to accept additional parameters for tracking normalization modes.
- Enhanced the __call__ methods to store normalization and unnormalization information in the complementary data of transitions.
- Added unit tests to verify the correct tracking of normalization info, including scenarios with missing stats and selective normalization keys.
* feat(factory): Add preprocessor and postprocessor overrides to ProcessorConfigKwargs
- Updated ProcessorConfigKwargs to include optional overrides for preprocessor and postprocessor configurations.
- Enhanced the make_processor function to utilize the new overrides, allowing for more flexible processor initialization.
* feat(processors): Integrate RenameProcessor into various processor configurations
- Added RenameProcessor to the input steps of multiple processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Consolidated normalization features from input and output into a single NormalizerProcessor for improved efficiency.
- Updated the input steps to ensure compatibility with the new RenameProcessor integration.
* feat(smolvla): Refactor language processing and introduce new line processor (#1658)
- Removed the prepare_language method and directly accessed language tokens and masks from the batch using the OBS_LANGUAGE constant.
- Added SmolVLANewLineProcessor to ensure tasks end with a newline, enhancing tokenization compatibility.
- Updated the make_smolvla_processor function to include the new line processor and tokenizer processor for improved input handling.
* feture(policies): add device processor (#1659)
* feat(processors): Integrate DeviceProcessor into multiple processor configurations
- Added DeviceProcessor to the input and output steps of various processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_pi0fast_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Enhanced the DeviceProcessor class with state management methods and ensured compatibility with existing processor pipelines.
- Introduced unit tests for DeviceProcessor to validate functionality across different scenarios, including CPU and CUDA operations.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Remove to() method for device management
- Eliminated the to() method from RobotProcessor, which was responsible for moving tensor states to specified devices.
- Removed associated unit tests that validated the functionality of the to() method across various scenarios.
- Streamlined the pipeline code by focusing on other device management strategies.
* feat(processor): Enhance DeviceProcessor with float dtype conversion
- Added support for optional float dtype conversion in DeviceProcessor, allowing tensors to be converted to specified floating-point types while preserving non-float types.
- Implemented validation for float dtype input and updated the processor's configuration methods to include float dtype.
- Refactored tensor processing logic to streamline device movement and dtype conversion.
- Introduced comprehensive unit tests to validate the new float dtype functionality across various scenarios.
* feat(policies): Add new line processors and update module exports
* feat(processor): Enhance batch and device processors to handle index and task_index fields
- Added logic to ToBatchProcessor for unsqueezing 0D tensors for index and task_index fields, ensuring they are processed as 1D tensors.
- Updated DeviceProcessor to process index and task_index fields in complementary data, preserving their tensor types and ensuring non-tensor fields remain unchanged.
- Enhanced unit tests to validate the correct handling of index and task_index fields across various scenarios, including device compatibility and dtype preservation.
* Add eval script
* fix `q_curr` in InverseKinematicsEEToJoints to the IK solution
* feat(processors): Introduce processors for various policy types
- Added `make_processor` function to create processor instances for different policy types, including `tdmpc`, `diffusion`, `act`, `vqbet`, `pi0`, `pi0fast`, `sac`, and `reward_classifier`.
- Implemented corresponding processor files for each policy type, encapsulating normalization and unnormalization steps.
- Updated existing policies to remove direct normalization dependencies, enhancing modularity and clarity.
- Enhanced test coverage to validate the integration of new processors with existing policy configurations.
* refactor(learner): Remove normalization from cached image features retrieval
- Simplified the retrieval of observation features by removing the normalization step from the `get_cached_image_features` method calls.
- This change enhances clarity and aligns with the recent updates to policy processors.
* refactor(policies): Remove unnormalization step from action predictions
- Eliminated the unnormalization of actions in both `TDMPCPolicy` and `VQBeTPolicy` classes to streamline action prediction.
- This change improves code clarity and aligns with recent updates to policy processors.
* feat(train): Integrate preprocessor into training pipeline
* refactor(train): Update preprocessor initialization to include dataset statistics
* refactor(policies): Enhance processor creation and add NaN detection hook
* feat(record): Integrate RobotProcessor into recording loop and update policy handling
- Added support for RobotProcessor in the record_loop function to enhance data processing capabilities.
- Updated the logic to reset both policy and processor when provided, ensuring proper state management.
- Modified action prediction to utilize the processor, improving the overall functionality of the recording process.
- Adjusted the save_checkpoint function to include preprocessor state saving, enhancing checkpointing capabilities.
* feat(migration): Add script for migrating policy models with normalization layers
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(migrate): Enhance migration script to create preprocessor and postprocessor for policy models
- Updated the migration script to generate both a preprocessor and a postprocessor, improving the handling of normalization for training and inference.
- Added functionality to convert features to PolicyFeature objects, ensuring compatibility with the new processor architecture.
- Refined the extraction and removal of normalization statistics and layers, streamlining the migration process.
- Improved error handling for missing mandatory configuration fields during model instantiation.
* feat(migrate): Add model card generation and saving to migration script
- Implemented functionality to generate and save a model card for the migrated model, including metadata such as dataset repository ID, license, and tags.
- Enhanced the script to push the model card to the hub if requested, improving model documentation and accessibility.
- Refactored the saving process to ensure the model card is saved locally and uploaded correctly when pushing to the hub.
* feat(processor): Introduce ToBatchProcessor for handling observation batching
- Added ToBatchProcessor to ensure observations have proper batch dimensions for model processing.
- Implemented functionality to add batch dimensions to state and image observations as needed.
- Created comprehensive unit tests to validate the processor's behavior with various tensor dimensions and types.
- Ensured compatibility with existing transition keys and maintained the integrity of non-observation data.
* feat(processors): Add ToBatchProcessor to multiple policy processors
- Integrated ToBatchProcessor into various policy processors to handle observation batching.
- Updated make functions for act, diffusion, pi0, pi0fast, sac, smolvla, tdmpc, and vqbet processors to include the new batching functionality.
- Ensured consistency across all processor implementations for improved data handling.
* refactor(factory): Remove unused imports and NaN detection hook from processor creation
* feat(batch_processor): Enhance ToBatchProcessor to handle action batching
- Updated ToBatchProcessor to add batch dimensions to actions in addition to observations.
- Implemented separate methods for processing observations and actions, improving code readability.
- Added comprehensive unit tests to validate action batching functionality across various tensor dimensions and types.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feat(factory): Enhance make_processor to support preprocessor and postprocessor configuration
- Introduced ProcessorConfigKwargs TypedDict for better type safety in processor configuration.
- Updated make_processor to accept preprocessor and postprocessor configuration filenames, improving flexibility in processor instantiation.
- Refactored the loading of pretrained processors to utilize the new configuration options.
* refactor(factory): Clean up imports in factory.py
- Removed unused import of IdentityProcessor to streamline the code.
* feat(migrate): Extend load_model_from_hub to include train configuration
- Updated load_model_from_hub to return the train configuration alongside the model state_dict and config.
- Modified main function to handle the additional train configuration when loading models from both the hub and local paths.
- Adjusted dataset_repo_id extraction to utilize the train configuration for improved accuracy.
* refactor(record): Rename processor parameters and update processing logic
- Renamed `processor` to `preprocessor` and added `postprocessor` parameter for clarity.
- Updated the `record_loop` and `predict_action` functions to utilize the new preprocessor and postprocessor, enhancing the processing flow.
- Ensured compatibility with existing functionality while improving code readability.
* feat(batch_processor): Add task field processing to ToBatchProcessor
- Enhanced ToBatchProcessor to wrap string tasks in a list, adding batch dimensions for compatibility with model inference.
- Implemented a new method for processing complementary data, ensuring that task values are correctly handled as either strings or lists of strings.
- Added comprehensive unit tests to validate task processing, including edge cases and in-place mutation of complementary data.
* feat(normalization): Implement IDENTITY mode for normalization and unnormalization
- Enhanced NormalizerProcessor and UnnormalizerProcessor to support IDENTITY mode, allowing features to bypass normalization when specified.
- Updated processing logic to check normalization modes and handle missing statistics gracefully.
- Added comprehensive unit tests to validate IDENTITY mode functionality for both observations and actions, ensuring correct behavior across various scenarios.
- Improved error handling for unsupported normalization modes.
* fix(rebase): remove residual normalization layer:
* refactor(diffusion): remove normalization layer from input processing
* refactor(normalization): Remove unused state dict transformation methods and streamline imports
- Eliminated the _transform_state_dict_keys and _load_as_safetensor methods from PI0Policy, simplifying the model loading process.
- Cleaned up imports in modeling_pi0.py by removing log_model_loading_keys and init_logging.
- Updated TDMPCPolicy and VQBeTPolicy to handle action removal from batches during offline evaluation.
- Introduced hotswap_stats function in normalize_processor.py to update normalization statistics dynamically, with corresponding tests to ensure functionality.
* refactor(normalization): Clean up imports in normalize_processor.py
* feat(batch_processor): Add feature_contract method to ToBatchProcessor
- Introduced feature_contract method that returns features without modification, maintaining the no-op behavior of the processor.
- This addition enhances the flexibility of the ToBatchProcessor for future feature processing needs.
* fix(dependencies): Update transformers dependency constraint to allow only versions up to 4.52.0
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* feature(pipeline): port tokenizer pipeline for VLA (#1645)
* feat(tokenizer): Introduce TokenizerProcessor for text tokenization
- Added TokenizerProcessor class to handle tokenization of task strings using Hugging Face's AutoTokenizer.
- Supports both string and list inputs, with customizable parameters for task key, output key, and tokenization settings.
- Implemented comprehensive unit tests to validate functionality, including handling of various input scenarios and integration with RobotProcessor.
- Updated types.py to include LANGUAGE feature type and modified __init__.py to register the new processor.
* feat(language): Enhance language processing in TokenizerProcessor
- Added OBS_LANGUAGE constant to define the observation language key.
- Updated TokenizerProcessor to store tokenized task data in the observation dictionary, ensuring compatibility with the new language feature.
- Introduced Pi0NewLineProcessor to append newlines to tasks for proper tokenization.
- Modified tests to validate the integration of language tokens and attention masks in the observation structure.
* feat(tokenizer): Add padding configuration to TokenizerProcessor
- Introduced `padding_side` parameter to the TokenizerProcessor for customizable padding direction.
- Updated the `make_pi0_processor` function to include the new padding configuration.
- Enhanced unit tests to validate the functionality of the `padding_side` parameter in various scenarios.
* feat(processor): Add state management methods to Pi0NewLineProcessor
* feat(normalization): Track normalization and unnormalization info in complementary data
- Updated NormalizerProcessor and UnnormalizerProcessor to accept additional parameters for tracking normalization modes.
- Enhanced the __call__ methods to store normalization and unnormalization information in the complementary data of transitions.
- Added unit tests to verify the correct tracking of normalization info, including scenarios with missing stats and selective normalization keys.
* feat(factory): Add preprocessor and postprocessor overrides to ProcessorConfigKwargs
- Updated ProcessorConfigKwargs to include optional overrides for preprocessor and postprocessor configurations.
- Enhanced the make_processor function to utilize the new overrides, allowing for more flexible processor initialization.
* feat(processors): Integrate RenameProcessor into various processor configurations
- Added RenameProcessor to the input steps of multiple processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Consolidated normalization features from input and output into a single NormalizerProcessor for improved efficiency.
- Updated the input steps to ensure compatibility with the new RenameProcessor integration.
* feat(smolvla): Refactor language processing and introduce new line processor (#1658)
- Removed the prepare_language method and directly accessed language tokens and masks from the batch using the OBS_LANGUAGE constant.
- Added SmolVLANewLineProcessor to ensure tasks end with a newline, enhancing tokenization compatibility.
- Updated the make_smolvla_processor function to include the new line processor and tokenizer processor for improved input handling.
* feture(policies): add device processor (#1659)
* feat(processors): Integrate DeviceProcessor into multiple processor configurations
- Added DeviceProcessor to the input and output steps of various processor functions, including make_act_processor, make_diffusion_processor, make_pi0_processor, make_pi0fast_processor, make_sac_processor, make_tdmpc_processor, make_vqbet_processor, and make_smolvla_processor.
- Enhanced the DeviceProcessor class with state management methods and ensured compatibility with existing processor pipelines.
- Introduced unit tests for DeviceProcessor to validate functionality across different scenarios, including CPU and CUDA operations.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* refactor(pipeline): Remove to() method for device management
- Eliminated the to() method from RobotProcessor, which was responsible for moving tensor states to specified devices.
- Removed associated unit tests that validated the functionality of the to() method across various scenarios.
- Streamlined the pipeline code by focusing on other device management strategies.
* feat(processor): Enhance DeviceProcessor with float dtype conversion
- Added support for optional float dtype conversion in DeviceProcessor, allowing tensors to be converted to specified floating-point types while preserving non-float types.
- Implemented validation for float dtype input and updated the processor's configuration methods to include float dtype.
- Refactored tensor processing logic to streamline device movement and dtype conversion.
- Introduced comprehensive unit tests to validate the new float dtype functionality across various scenarios.
* feat(policies): Add new line processors and update module exports
* feat(processor): Enhance batch and device processors to handle index and task_index fields
- Added logic to ToBatchProcessor for unsqueezing 0D tensors for index and task_index fields, ensuring they are processed as 1D tensors.
- Updated DeviceProcessor to process index and task_index fields in complementary data, preserving their tensor types and ensuring non-tensor fields remain unchanged.
- Enhanced unit tests to validate the correct handling of index and task_index fields across various scenarios, including device compatibility and dtype preservation.
* refactor(processors): Standardize processor naming conventions
- Updated processor names across various files to use a consistent "robot_preprocessor" and "robot_postprocessor" format.
- Modified the make_processor functions in factory, act, diffusion, pi0, pi0fast, sac, smolvla, tdmpc, and vqbet to reflect the new naming scheme.
- Enhanced the pipeline configuration to align with the updated processor names, improving clarity and maintainability.
* refactor(factory): Update processor configuration and type hints
- Changed return type of get_policy_class to type[PreTrainedPolicy] for improved type safety.
- Enhanced make_processor function to utilize dataset_stats in processor creation for better flexibility.
- Updated ProcessorConfigKwargs to include dataset_stats, allowing for more comprehensive processor configurations.
- Streamlined processor initialization by removing unnecessary kwargs and ensuring clarity in processor type handling.
* Fix eval and android gripper
* add some tests
* refactor(factory, pi0fast): Update processor function names and parameters
- Renamed make_pi0_processor to make_pi0fast_processor for clarity and consistency.
- Updated parameter names in the factory's make_processor function to use pretrained_model_name_or_path instead of source, enhancing readability and alignment with naming conventions.
* fix(train.py) push postprocessor with preprocessor
- Add preprocesser policy overrides for device and rename_map
- Add rename_map to DatasetRecordConfig (record.py)
* Cleanup pr
* fix more git diff pr issues
* add path as type in save_pretrained
* small nit
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* rename test file
* fix: make dataset_features/feature_contract is optional
* fix tests
* Encorperate pr feedback
* clean up record.py
* add ascii art, fix normal record
* remove merge issues
* fix merge
* remove features
* Add feedback PR
* fix last 4 tests
* remove features check
* rename to transform_features
* add transform_features
* fix lekiwi eval and update eval api example
---------
Signed-off-by: Adil Zouitine <adilzouitinegm@gmail.com>
Signed-off-by: Pepijn <138571049+pkooij@users.noreply.github.com>
Co-authored-by: Adil Zouitine <adilzouitinegm@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Simon Alibert <75076266+aliberts@users.noreply.github.com>
Co-authored-by: Michel Aractingi <michel.aractingi@huggingface.co>
2025-08-07 16:13:34 +02:00
|
|
|
|
out = step.transform_features(features)
|
2025-07-31 16:29:48 +02:00
|
|
|
|
features = out
|
|
|
|
|
|
return features
|
|
|
|
|
|
|
2025-09-03 12:28:40 +02:00
|
|
|
|
def process_observation(self, observation: dict[str, Any]) -> dict[str, Any]:
|
|
|
|
|
|
transition: EnvTransition = create_transition(observation=observation)
|
|
|
|
|
|
transformed_transition = self._forward(transition)
|
|
|
|
|
|
return transformed_transition[TransitionKey.OBSERVATION]
|
|
|
|
|
|
|
|
|
|
|
|
def process_action(self, action: Any | torch.Tensor) -> Any | torch.Tensor:
|
|
|
|
|
|
transition: EnvTransition = create_transition(action=action)
|
|
|
|
|
|
transformed_transition = self._forward(transition)
|
|
|
|
|
|
return transformed_transition[TransitionKey.ACTION]
|
|
|
|
|
|
|
|
|
|
|
|
def process_reward(self, reward: float | torch.Tensor) -> float | torch.Tensor:
|
|
|
|
|
|
transition: EnvTransition = create_transition(reward=reward)
|
|
|
|
|
|
transformed_transition = self._forward(transition)
|
|
|
|
|
|
return transformed_transition[TransitionKey.REWARD]
|
|
|
|
|
|
|
|
|
|
|
|
def process_done(self, done: bool | torch.Tensor) -> bool | torch.Tensor:
|
|
|
|
|
|
transition: EnvTransition = create_transition(done=done)
|
|
|
|
|
|
transformed_transition = self._forward(transition)
|
|
|
|
|
|
return transformed_transition[TransitionKey.DONE]
|
|
|
|
|
|
|
|
|
|
|
|
def process_truncated(self, truncated: bool | torch.Tensor) -> bool | torch.Tensor:
|
|
|
|
|
|
transition: EnvTransition = create_transition(truncated=truncated)
|
|
|
|
|
|
transformed_transition = self._forward(transition)
|
|
|
|
|
|
return transformed_transition[TransitionKey.TRUNCATED]
|
|
|
|
|
|
|
|
|
|
|
|
def process_info(self, info: dict[str, Any]) -> dict[str, Any]:
|
|
|
|
|
|
transition: EnvTransition = create_transition(info=info)
|
|
|
|
|
|
transformed_transition = self._forward(transition)
|
|
|
|
|
|
return transformed_transition[TransitionKey.INFO]
|
|
|
|
|
|
|
|
|
|
|
|
def process_complementary_data(self, complementary_data: dict[str, Any]) -> dict[str, Any]:
|
|
|
|
|
|
transition: EnvTransition = create_transition(complementary_data=complementary_data)
|
|
|
|
|
|
transformed_transition = self._forward(transition)
|
|
|
|
|
|
return transformed_transition[TransitionKey.COMPLEMENTARY_DATA]
|
|
|
|
|
|
|
2025-07-04 10:53:40 +02:00
|
|
|
|
|
2025-09-03 17:30:47 +02:00
|
|
|
|
class ObservationProcessorStep(ProcessorStep, ABC):
|
2025-07-04 11:07:18 +02:00
|
|
|
|
"""Base class for processors that modify only the observation component of a transition.
|
|
|
|
|
|
|
|
|
|
|
|
Subclasses should override the `observation` method to implement custom observation processing.
|
|
|
|
|
|
This class handles the boilerplate of extracting and reinserting the processed observation
|
2025-07-21 14:54:31 +02:00
|
|
|
|
into the transition dict, eliminating the need to implement the `__call__` method in subclasses.
|
2025-07-04 11:07:18 +02:00
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
```python
|
|
|
|
|
|
class MyObservationScaler(ObservationProcessor):
|
|
|
|
|
|
def __init__(self, scale_factor):
|
|
|
|
|
|
self.scale_factor = scale_factor
|
|
|
|
|
|
|
|
|
|
|
|
def observation(self, observation):
|
|
|
|
|
|
return observation * self.scale_factor
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2025-07-21 14:54:31 +02:00
|
|
|
|
By inheriting from this class, you avoid writing repetitive code to handle transition dict
|
2025-07-04 11:07:18 +02:00
|
|
|
|
manipulation, focusing only on the specific observation processing logic.
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
2025-08-31 20:38:52 +02:00
|
|
|
|
@abstractmethod
|
|
|
|
|
|
def observation(self, observation) -> dict[str, Any]:
|
2025-07-04 11:07:18 +02:00
|
|
|
|
"""Process the observation component.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
observation: The observation to process
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
The processed observation
|
|
|
|
|
|
"""
|
2025-08-31 20:38:52 +02:00
|
|
|
|
...
|
2025-07-04 10:53:40 +02:00
|
|
|
|
|
|
|
|
|
|
def __call__(self, transition: EnvTransition) -> EnvTransition:
|
2025-08-31 20:38:52 +02:00
|
|
|
|
self._current_transition = transition.copy()
|
|
|
|
|
|
new_transition = self._current_transition
|
|
|
|
|
|
|
|
|
|
|
|
observation = new_transition.get(TransitionKey.OBSERVATION)
|
2025-08-06 14:00:13 +02:00
|
|
|
|
if observation is None:
|
2025-08-31 20:38:52 +02:00
|
|
|
|
return new_transition
|
2025-08-06 14:00:13 +02:00
|
|
|
|
|
2025-07-21 14:54:31 +02:00
|
|
|
|
processed_observation = self.observation(observation)
|
|
|
|
|
|
new_transition[TransitionKey.OBSERVATION] = processed_observation
|
|
|
|
|
|
return new_transition
|
2025-07-04 10:53:40 +02:00
|
|
|
|
|
2025-08-05 10:31:09 +02:00
|
|
|
|
|
2025-09-03 17:30:47 +02:00
|
|
|
|
class ActionProcessorStep(ProcessorStep, ABC):
|
2025-07-04 11:07:18 +02:00
|
|
|
|
"""Base class for processors that modify only the action component of a transition.
|
|
|
|
|
|
|
|
|
|
|
|
Subclasses should override the `action` method to implement custom action processing.
|
|
|
|
|
|
This class handles the boilerplate of extracting and reinserting the processed action
|
2025-07-21 14:54:31 +02:00
|
|
|
|
into the transition dict, eliminating the need to implement the `__call__` method in subclasses.
|
2025-07-04 11:07:18 +02:00
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
```python
|
|
|
|
|
|
class ActionClipping(ActionProcessor):
|
|
|
|
|
|
def __init__(self, min_val, max_val):
|
|
|
|
|
|
self.min_val = min_val
|
|
|
|
|
|
self.max_val = max_val
|
|
|
|
|
|
|
|
|
|
|
|
def action(self, action):
|
|
|
|
|
|
return np.clip(action, self.min_val, self.max_val)
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2025-07-21 14:54:31 +02:00
|
|
|
|
By inheriting from this class, you avoid writing repetitive code to handle transition dict
|
2025-07-04 11:07:18 +02:00
|
|
|
|
manipulation, focusing only on the specific action processing logic.
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
2025-08-31 20:38:52 +02:00
|
|
|
|
@abstractmethod
|
|
|
|
|
|
def action(self, action) -> Any | torch.Tensor:
|
2025-07-04 11:07:18 +02:00
|
|
|
|
"""Process the action component.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
action: The action to process
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
The processed action
|
|
|
|
|
|
"""
|
2025-08-31 20:38:52 +02:00
|
|
|
|
...
|
2025-07-04 10:53:40 +02:00
|
|
|
|
|
|
|
|
|
|
def __call__(self, transition: EnvTransition) -> EnvTransition:
|
2025-08-31 20:38:52 +02:00
|
|
|
|
self._current_transition = transition.copy()
|
|
|
|
|
|
new_transition = self._current_transition
|
|
|
|
|
|
|
|
|
|
|
|
action = new_transition.get(TransitionKey.ACTION)
|
2025-08-06 14:00:13 +02:00
|
|
|
|
if action is None:
|
2025-08-31 20:38:52 +02:00
|
|
|
|
return new_transition
|
2025-08-06 14:00:13 +02:00
|
|
|
|
|
2025-07-21 14:54:31 +02:00
|
|
|
|
processed_action = self.action(action)
|
|
|
|
|
|
new_transition[TransitionKey.ACTION] = processed_action
|
|
|
|
|
|
return new_transition
|
2025-07-04 10:53:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
2025-09-03 17:30:47 +02:00
|
|
|
|
class RewardProcessorStep(ProcessorStep, ABC):
|
2025-07-04 11:07:18 +02:00
|
|
|
|
"""Base class for processors that modify only the reward component of a transition.
|
|
|
|
|
|
|
|
|
|
|
|
Subclasses should override the `reward` method to implement custom reward processing.
|
|
|
|
|
|
This class handles the boilerplate of extracting and reinserting the processed reward
|
2025-07-21 14:54:31 +02:00
|
|
|
|
into the transition dict, eliminating the need to implement the `__call__` method in subclasses.
|
2025-07-04 11:07:18 +02:00
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
```python
|
|
|
|
|
|
class RewardScaler(RewardProcessor):
|
|
|
|
|
|
def __init__(self, scale_factor):
|
|
|
|
|
|
self.scale_factor = scale_factor
|
|
|
|
|
|
|
|
|
|
|
|
def reward(self, reward):
|
|
|
|
|
|
return reward * self.scale_factor
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2025-07-21 14:54:31 +02:00
|
|
|
|
By inheriting from this class, you avoid writing repetitive code to handle transition dict
|
2025-07-04 11:07:18 +02:00
|
|
|
|
manipulation, focusing only on the specific reward processing logic.
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
2025-08-31 20:38:52 +02:00
|
|
|
|
@abstractmethod
|
|
|
|
|
|
def reward(self, reward) -> float | torch.Tensor:
|
2025-07-04 11:07:18 +02:00
|
|
|
|
"""Process the reward component.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
reward: The reward to process
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
The processed reward
|
|
|
|
|
|
"""
|
2025-08-31 20:38:52 +02:00
|
|
|
|
...
|
2025-07-04 10:53:40 +02:00
|
|
|
|
|
|
|
|
|
|
def __call__(self, transition: EnvTransition) -> EnvTransition:
|
2025-08-31 20:38:52 +02:00
|
|
|
|
self._current_transition = transition.copy()
|
|
|
|
|
|
new_transition = self._current_transition
|
|
|
|
|
|
|
|
|
|
|
|
reward = new_transition.get(TransitionKey.REWARD)
|
2025-08-06 14:00:13 +02:00
|
|
|
|
if reward is None:
|
2025-08-31 20:38:52 +02:00
|
|
|
|
return new_transition
|
2025-08-06 14:00:13 +02:00
|
|
|
|
|
2025-07-21 14:54:31 +02:00
|
|
|
|
processed_reward = self.reward(reward)
|
|
|
|
|
|
new_transition[TransitionKey.REWARD] = processed_reward
|
|
|
|
|
|
return new_transition
|
2025-07-04 10:53:40 +02:00
|
|
|
|
|
2025-08-05 10:31:09 +02:00
|
|
|
|
|
2025-09-03 17:30:47 +02:00
|
|
|
|
class DoneProcessorStep(ProcessorStep, ABC):
|
2025-07-04 11:07:18 +02:00
|
|
|
|
"""Base class for processors that modify only the done flag of a transition.
|
|
|
|
|
|
|
|
|
|
|
|
Subclasses should override the `done` method to implement custom done flag processing.
|
|
|
|
|
|
This class handles the boilerplate of extracting and reinserting the processed done flag
|
2025-07-21 14:54:31 +02:00
|
|
|
|
into the transition dict, eliminating the need to implement the `__call__` method in subclasses.
|
2025-07-04 11:07:18 +02:00
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
```python
|
|
|
|
|
|
class TimeoutDone(DoneProcessor):
|
|
|
|
|
|
def __init__(self, max_steps):
|
|
|
|
|
|
self.steps = 0
|
|
|
|
|
|
self.max_steps = max_steps
|
|
|
|
|
|
|
|
|
|
|
|
def done(self, done):
|
|
|
|
|
|
self.steps += 1
|
|
|
|
|
|
return done or self.steps >= self.max_steps
|
|
|
|
|
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
|
|
self.steps = 0
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2025-07-21 14:54:31 +02:00
|
|
|
|
By inheriting from this class, you avoid writing repetitive code to handle transition dict
|
2025-07-04 11:07:18 +02:00
|
|
|
|
manipulation, focusing only on the specific done flag processing logic.
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
2025-08-31 20:38:52 +02:00
|
|
|
|
@abstractmethod
|
|
|
|
|
|
def done(self, done) -> bool | torch.Tensor:
|
2025-07-04 11:07:18 +02:00
|
|
|
|
"""Process the done flag.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
done: The done flag to process
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
The processed done flag
|
|
|
|
|
|
"""
|
2025-08-31 20:38:52 +02:00
|
|
|
|
...
|
2025-07-04 10:53:40 +02:00
|
|
|
|
|
|
|
|
|
|
def __call__(self, transition: EnvTransition) -> EnvTransition:
|
2025-08-31 20:38:52 +02:00
|
|
|
|
self._current_transition = transition.copy()
|
|
|
|
|
|
new_transition = self._current_transition
|
|
|
|
|
|
|
|
|
|
|
|
done = new_transition.get(TransitionKey.DONE)
|
2025-08-06 14:00:13 +02:00
|
|
|
|
if done is None:
|
2025-08-31 20:38:52 +02:00
|
|
|
|
return new_transition
|
2025-08-06 14:00:13 +02:00
|
|
|
|
|
2025-07-21 14:54:31 +02:00
|
|
|
|
processed_done = self.done(done)
|
|
|
|
|
|
new_transition[TransitionKey.DONE] = processed_done
|
|
|
|
|
|
return new_transition
|
2025-07-04 10:53:40 +02:00
|
|
|
|
|
2025-08-05 10:31:09 +02:00
|
|
|
|
|
2025-09-03 17:30:47 +02:00
|
|
|
|
class TruncatedProcessorStep(ProcessorStep, ABC):
|
2025-07-04 11:07:18 +02:00
|
|
|
|
"""Base class for processors that modify only the truncated flag of a transition.
|
|
|
|
|
|
|
|
|
|
|
|
Subclasses should override the `truncated` method to implement custom truncated flag processing.
|
|
|
|
|
|
This class handles the boilerplate of extracting and reinserting the processed truncated flag
|
2025-07-21 14:54:31 +02:00
|
|
|
|
into the transition dict, eliminating the need to implement the `__call__` method in subclasses.
|
2025-07-04 11:07:18 +02:00
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
```python
|
|
|
|
|
|
class EarlyTruncation(TruncatedProcessor):
|
|
|
|
|
|
def __init__(self, threshold):
|
|
|
|
|
|
self.threshold = threshold
|
|
|
|
|
|
|
|
|
|
|
|
def truncated(self, truncated):
|
|
|
|
|
|
# Additional truncation condition
|
|
|
|
|
|
return truncated or some_condition > self.threshold
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2025-07-21 14:54:31 +02:00
|
|
|
|
By inheriting from this class, you avoid writing repetitive code to handle transition dict
|
2025-07-04 11:07:18 +02:00
|
|
|
|
manipulation, focusing only on the specific truncated flag processing logic.
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
2025-08-31 20:38:52 +02:00
|
|
|
|
@abstractmethod
|
|
|
|
|
|
def truncated(self, truncated) -> bool | torch.Tensor:
|
2025-07-04 11:07:18 +02:00
|
|
|
|
"""Process the truncated flag.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
truncated: The truncated flag to process
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
The processed truncated flag
|
|
|
|
|
|
"""
|
2025-08-31 20:38:52 +02:00
|
|
|
|
...
|
2025-07-04 10:53:40 +02:00
|
|
|
|
|
|
|
|
|
|
def __call__(self, transition: EnvTransition) -> EnvTransition:
|
2025-08-31 20:38:52 +02:00
|
|
|
|
self._current_transition = transition.copy()
|
|
|
|
|
|
new_transition = self._current_transition
|
|
|
|
|
|
|
|
|
|
|
|
truncated = new_transition.get(TransitionKey.TRUNCATED)
|
2025-08-06 14:00:13 +02:00
|
|
|
|
if truncated is None:
|
2025-08-31 20:38:52 +02:00
|
|
|
|
return new_transition
|
2025-08-06 14:00:13 +02:00
|
|
|
|
|
2025-07-21 14:54:31 +02:00
|
|
|
|
processed_truncated = self.truncated(truncated)
|
|
|
|
|
|
new_transition[TransitionKey.TRUNCATED] = processed_truncated
|
|
|
|
|
|
return new_transition
|
2025-07-04 10:53:40 +02:00
|
|
|
|
|
2025-08-05 10:31:09 +02:00
|
|
|
|
|
2025-09-03 17:30:47 +02:00
|
|
|
|
class InfoProcessorStep(ProcessorStep, ABC):
|
2025-07-04 11:07:18 +02:00
|
|
|
|
"""Base class for processors that modify only the info dictionary of a transition.
|
|
|
|
|
|
|
|
|
|
|
|
Subclasses should override the `info` method to implement custom info processing.
|
|
|
|
|
|
This class handles the boilerplate of extracting and reinserting the processed info
|
2025-07-21 14:54:31 +02:00
|
|
|
|
into the transition dict, eliminating the need to implement the `__call__` method in subclasses.
|
2025-07-04 11:07:18 +02:00
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
```python
|
|
|
|
|
|
class InfoAugmenter(InfoProcessor):
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
self.step_count = 0
|
|
|
|
|
|
|
|
|
|
|
|
def info(self, info):
|
|
|
|
|
|
info = info.copy() # Create a copy to avoid modifying the original
|
2025-07-21 08:06:31 +00:00
|
|
|
|
info["steps"] = self.step_count
|
2025-07-04 11:07:18 +02:00
|
|
|
|
self.step_count += 1
|
|
|
|
|
|
return info
|
|
|
|
|
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
|
|
self.step_count = 0
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2025-07-21 14:54:31 +02:00
|
|
|
|
By inheriting from this class, you avoid writing repetitive code to handle transition dict
|
2025-07-04 11:07:18 +02:00
|
|
|
|
manipulation, focusing only on the specific info dictionary processing logic.
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
2025-08-31 20:38:52 +02:00
|
|
|
|
@abstractmethod
|
|
|
|
|
|
def info(self, info) -> dict[str, Any]:
|
2025-07-04 11:07:18 +02:00
|
|
|
|
"""Process the info dictionary.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
info: The info dictionary to process
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
The processed info dictionary
|
|
|
|
|
|
"""
|
2025-08-31 20:38:52 +02:00
|
|
|
|
...
|
2025-07-04 10:53:40 +02:00
|
|
|
|
|
|
|
|
|
|
def __call__(self, transition: EnvTransition) -> EnvTransition:
|
2025-08-31 20:38:52 +02:00
|
|
|
|
self._current_transition = transition.copy()
|
|
|
|
|
|
new_transition = self._current_transition
|
|
|
|
|
|
|
|
|
|
|
|
info = new_transition.get(TransitionKey.INFO)
|
2025-08-06 14:00:13 +02:00
|
|
|
|
if info is None:
|
2025-08-31 20:38:52 +02:00
|
|
|
|
return new_transition
|
2025-08-06 14:00:13 +02:00
|
|
|
|
|
2025-07-21 14:54:31 +02:00
|
|
|
|
processed_info = self.info(info)
|
|
|
|
|
|
new_transition[TransitionKey.INFO] = processed_info
|
|
|
|
|
|
return new_transition
|
2025-07-06 21:29:51 +02:00
|
|
|
|
|
2025-08-05 10:31:09 +02:00
|
|
|
|
|
2025-09-03 17:30:47 +02:00
|
|
|
|
class ComplementaryDataProcessorStep(ProcessorStep, ABC):
|
2025-07-09 19:20:43 +02:00
|
|
|
|
"""Base class for processors that modify only the complementary data of a transition.
|
|
|
|
|
|
|
|
|
|
|
|
Subclasses should override the `complementary_data` method to implement custom complementary data processing.
|
|
|
|
|
|
This class handles the boilerplate of extracting and reinserting the processed complementary data
|
2025-07-21 14:54:31 +02:00
|
|
|
|
into the transition dict, eliminating the need to implement the `__call__` method in subclasses.
|
2025-07-09 19:20:43 +02:00
|
|
|
|
"""
|
|
|
|
|
|
|
2025-08-31 20:38:52 +02:00
|
|
|
|
@abstractmethod
|
|
|
|
|
|
def complementary_data(self, complementary_data) -> dict[str, Any]:
|
2025-07-09 19:20:43 +02:00
|
|
|
|
"""Process the complementary data.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
complementary_data: The complementary data to process
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
The processed complementary data
|
|
|
|
|
|
"""
|
2025-08-31 20:38:52 +02:00
|
|
|
|
...
|
2025-07-09 19:20:43 +02:00
|
|
|
|
|
|
|
|
|
|
def __call__(self, transition: EnvTransition) -> EnvTransition:
|
2025-08-31 20:38:52 +02:00
|
|
|
|
self._current_transition = transition.copy()
|
|
|
|
|
|
new_transition = self._current_transition
|
|
|
|
|
|
|
|
|
|
|
|
complementary_data = new_transition.get(TransitionKey.COMPLEMENTARY_DATA)
|
2025-08-06 14:00:13 +02:00
|
|
|
|
if complementary_data is None:
|
2025-08-31 20:38:52 +02:00
|
|
|
|
return new_transition
|
2025-08-06 14:00:13 +02:00
|
|
|
|
|
2025-07-21 14:54:31 +02:00
|
|
|
|
processed_complementary_data = self.complementary_data(complementary_data)
|
|
|
|
|
|
new_transition[TransitionKey.COMPLEMENTARY_DATA] = processed_complementary_data
|
|
|
|
|
|
return new_transition
|
2025-07-09 19:20:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
2025-09-03 17:30:47 +02:00
|
|
|
|
class IdentityProcessorStep(ProcessorStep):
|
2025-07-06 21:29:51 +02:00
|
|
|
|
"""Identity processor that does nothing."""
|
|
|
|
|
|
|
|
|
|
|
|
def __call__(self, transition: EnvTransition) -> EnvTransition:
|
|
|
|
|
|
return transition
|
2025-09-02 17:15:01 +02:00
|
|
|
|
|
|
|
|
|
|
def transform_features(self, features: dict[str, PolicyFeature]) -> dict[str, PolicyFeature]:
|
|
|
|
|
|
return features
|