action_tokenizer
action_tokenizer
¶
Action tokenizer for continuous-action discretizers and model token IDs.
ActionTokenizer
¶
ActionTokenizer(action_discretizer=None, token_id_mapping=None, max_token_len=256, pad_token_id=0, device=None)
Tokenizes continuous action chunks for discrete action-token decoders.
A single action chunk has shape (time_horizon, action_dim). A batch of chunks has shape (batch_size, time_horizon, action_dim). Encoded model token tensors have shape (max_token_len,) for one chunk or (batch_size, max_token_len) for a batch.
The tokenizer has two explicit parts: - an action discretizer, e.g. FAST or per-value binning; - a token-id mapping, e.g. identity IDs or language-tokenizer tail IDs.
The class owns sequence behavior: EOS, padding, masks, and batch dispatch.
Initialize action tokenizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_discretizer
|
ActionDiscretizer | None
|
Continuous-action discretizer. Defaults to FAST. |
None
|
token_id_mapping
|
ActionTokenIdMapping | None
|
Mapping from action-local IDs to model token IDs. Defaults to identity. |
None
|
max_token_len
|
int
|
Maximum token sequence length after EOS and padding. |
256
|
pad_token_id
|
int
|
Token ID to use for padding. |
0
|
device
|
device | None
|
Target device for returned token tensors. |
None
|
Source code in src/versatil/data/tokenization/action_tokenizer.py
fit
¶
Fit the action discretizer on normalized action chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_chunks
|
ndarray
|
Array with shape (num_chunks, time_horizon, action_dim). |
required |
Source code in src/versatil/data/tokenization/action_tokenizer.py
encode_chunk
¶
Encode one normalized action chunk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_chunk
|
ndarray | Tensor
|
Array or tensor with shape (time_horizon, action_dim). |
required |
is_pad_mask
|
Tensor | ndarray | None
|
Optional boolean mask with shape (time_horizon,), where True marks padded action rows to drop before tokenization. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
Dictionary containing token IDs and token padding mask, each with |
dict[str, Tensor]
|
shape (max_token_len,). |
Source code in src/versatil/data/tokenization/action_tokenizer.py
encode_batch
¶
Encode a batch of normalized action chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_chunks
|
ndarray | Tensor
|
Array or tensor with shape (batch_size, time_horizon, action_dim). |
required |
is_pad_mask
|
Tensor | ndarray | None
|
Optional boolean mask with shape (batch_size, time_horizon), where True marks padded action rows. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
Dictionary containing token IDs and token padding mask, each with |
dict[str, Tensor]
|
shape (batch_size, max_token_len). |
Source code in src/versatil/data/tokenization/action_tokenizer.py
encode
¶
Encode one action chunk or a batch of action chunks.
2D input must have shape (time_horizon, action_dim). 3D input must have shape (batch_size, time_horizon, action_dim).
Source code in src/versatil/data/tokenization/action_tokenizer.py
decode_chunk
¶
Decode one model token sequence into one action chunk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokens
|
Tensor | list[int] | ndarray
|
1D model token IDs with shape (token_sequence_len,). The sequence may include EOS and trailing padding IDs. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Normalized action chunk with shape (time_horizon, action_dim). |
Source code in src/versatil/data/tokenization/action_tokenizer.py
decode_batch
¶
Decode a batch of model token sequences into action chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokens
|
Tensor | ndarray
|
2D model token IDs with shape (batch_size, token_sequence_len). Sequences may include EOS and trailing padding IDs. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Normalized action chunks with shape |
ndarray
|
(batch_size, time_horizon, action_dim). |
Source code in src/versatil/data/tokenization/action_tokenizer.py
decode
¶
Decode one model token sequence or a batch of model token sequences.
1D token input has shape (token_sequence_len,) and returns shape (time_horizon, action_dim). 2D token input has shape (batch_size, token_sequence_len) and returns shape (batch_size, time_horizon, action_dim).
Source code in src/versatil/data/tokenization/action_tokenizer.py
to
¶
save_pretrained
¶
Save tokenizer state and optional external assets.
Source code in src/versatil/data/tokenization/action_tokenizer.py
state_dict
¶
Get serializable tokenizer state.
Source code in src/versatil/data/tokenization/action_tokenizer.py
load_state_dict
¶
Load tokenizer state.
Source code in src/versatil/data/tokenization/action_tokenizer.py
from_pretrained
classmethod
¶
Load tokenizer from disk.