UniformActionTokenizer#
- class torchrl.data.vla.UniformActionTokenizer(num_bins: int, *, low: float | Tensor, high: float | Tensor, action_dim: int | None = None)[source]#
Per-dimension uniform-bin action tokenizer (RT-2 / OpenVLA style).
Each action dimension is discretized into
num_binsequal-width bins over[low, high];encode()returns the bin index anddecode()returns the bin center. The round-trip is lossy with error bounded by half a bin width,(high - low) / (2 * num_bins).- Parameters:
num_bins (int) – number of bins per action dimension.
- Keyword Arguments:
low (float or torch.Tensor) – per-dimension lower bound. Actions are clamped to
[low, high]before binning.high (float or torch.Tensor) – per-dimension upper bound.
action_dim (int, optional) – action dimensionality. Required only when
low/highare scalars and you want a per-dimension shape.
Examples
>>> import torch >>> from torchrl.data.vla import UniformActionTokenizer >>> tok = UniformActionTokenizer(256, low=-1.0, high=1.0) >>> tokens = tok.encode(torch.tensor([-1.0, 0.0, 1.0])) >>> tokens tensor([ 0, 128, 255]) >>> torch.allclose(tok.decode(tokens), torch.tensor([-0.998, 0.002, 0.998]), atol=1e-2) True >>> tok.vocab_size 256
See also
RobotDatasetMetadatacarries theaction_low/action_highbounds used byfrom_metadata().- property action_dim: int | None#
The per-dimension action size, or
Nonefor scalar bounds.
- encode(actions: Tensor) Tensor[source]#
Map continuous actions
[..., action_dim]to token ids (long).
- classmethod from_metadata(metadata: RobotDatasetMetadata, num_bins: int) UniformActionTokenizer[source]#
Build from the
action_low/action_highof aRobotDatasetMetadata.
- property vocab_size: int#
Number of distinct token ids the tokenizer can emit per position.