Skip to content

behavior_cloning

behavior_cloning

Behavioral Cloning (BC) algorithm for supervised action prediction.

For multi-modal action prediction with latent variables, use:

VariationalAlgorithm(BehavioralCloning(), VAETransformerEncoder(...))

This provides the same functionality as the old BehavioralCloning with latent_encoder, but with a cleaner compositional design.

BehavioralCloning

BehavioralCloning()

Bases: DecodingAlgorithm

Pure Behavioral Cloning algorithm without variational inference.

Simplest imitation learning approach: directly predicts actions from observations using supervised learning. The network is trained to minimize the difference between predicted and ground-truth actions.

This is a deterministic, uni-modal algorithm. For multi-modal action prediction, wrap with VariationalAlgorithm: VariationalAlgorithm(BehavioralCloning(), VAETransformerEncoder(...))

Initialize Behavioral Cloning algorithm.

Source code in src/versatil/models/decoding/algorithm/behavior_cloning.py
def __init__(self):
    """Initialize Behavioral Cloning algorithm."""
    super().__init__()

forward

forward(network, features, actions=None)

Forward pass during training.

Parameters:

Name Type Description Default
network ActionDecoder

The action decoder network module

required
features dict[str, Tensor]

Dictionary of encoded features from the encoding pipeline.

required
actions dict[str, Tensor] | None

Optional dictionary of ground truth actions, if architecture requires it (e.g., DETR).

None

Returns:

Type Description
dict[str, Tensor]

Decoder output dictionary containing action predictions and any architecture-specific outputs.

dict[str, Tensor]

Keys typically include: - 'position_action': Predicted position actions (B, T, D_pos) - 'orientation_action': Predicted orientation actions if used (B, T, D_ori) - 'gripper_action': Predicted gripper actions if used (B, T, D_grip) - Additional architecture-specific outputs (e.g., 'is_pad')

Source code in src/versatil/models/decoding/algorithm/behavior_cloning.py
def forward(
    self,
    network: ActionDecoder,
    features: dict[str, torch.Tensor],
    actions: dict[str, torch.Tensor] | None = None,
) -> dict[str, torch.Tensor]:
    """Forward pass during training.

    Args:
        network: The action decoder network module
        features: Dictionary of encoded features from the encoding pipeline.
        actions: Optional dictionary of ground truth actions, if architecture requires it (e.g., DETR).

    Returns:
        Decoder output dictionary containing action predictions and any architecture-specific outputs.
        Keys typically include:
            - 'position_action': Predicted position actions (B, T, D_pos)
            - 'orientation_action': Predicted orientation actions if used (B, T, D_ori)
            - 'gripper_action': Predicted gripper actions if used (B, T, D_grip)
            - Additional architecture-specific outputs (e.g., 'is_pad')
    """
    return network(features=features, actions=actions)

predict

predict(network, features)

Inference/prediction pass.

Parameters:

Name Type Description Default
network ActionDecoder

The action decoder network module

required
features dict[str, Tensor]

Dict of encoded features from encoding pipeline

required

Returns:

Type Description
dict[str, Tensor]

Decoder output dictionary containing action predictions.

dict[str, Tensor]

Keys typically include: - 'position_action': Predicted position actions (B, T, D_pos) - 'orientation_action': Predicted orientation actions if used (B, T, D_ori) - 'gripper_action': Predicted gripper actions if used (B, T, D_grip)

Source code in src/versatil/models/decoding/algorithm/behavior_cloning.py
def predict(
    self,
    network: ActionDecoder,
    features: dict[str, torch.Tensor],
) -> dict[str, torch.Tensor]:
    """Inference/prediction pass.

    Args:
        network: The action decoder network module
        features: Dict of encoded features from encoding pipeline

    Returns:
        Decoder output dictionary containing action predictions.
        Keys typically include:
            - 'position_action': Predicted position actions (B, T, D_pos)
            - 'orientation_action': Predicted orientation actions if used (B, T, D_ori)
            - 'gripper_action': Predicted gripper actions if used (B, T, D_grip)
    """
    return network(features=features, actions=None)