Skip to content

Support Decision Transformer: tokenizer-optional load and tensor calibration inputs #4755

Closed

Description

@Lumea-art

What

Decision Transformer (decision_transformer, offline-RL sequence models) is not quantizable today. This issue records what blocks it, what already works in our favor, and a plan that keeps the blast radius inside a new definition plus one opt-in calibration path.

Evidence: today's failure

A tiny DecisionTransformerModel checkpoint (config.json + model.safetensors, no tokenizer) fails before model selection:

GPTQModel.load(ckpt, quantize_config=QuantizeConfig(bits=4, group_size=32))
ValueError: Couldn't instantiate the backend tokenizer from one of:
 (1) a `tokenizers` library serialization file, ...

Passing tokenizer=None does not change it. Decision-Transformer checkpoints never ship a tokenizer, so the text path cannot start.

Three things need to change

1. The registry has no definition

SUPPORTED_MODELS has 206 entries and no decision_transformer:

>>> [m for m in SUPPORTED_MODELS if "decision" in m]
[]

(openvla is present, so robot VLA policies that sit on a Llama decoder are already covered; this issue is about the tensor-input sequence models.)

2. Calibration rejects tensor-only samples

gptqmodel/utils/calibration.py:641:

raise ValueError(
    f"Quantize: unsupported calibration example structure at index {idx}: keys={list(example.keys())}"
)

Observed with a real sample:

ValueError: Quantize: unsupported calibration example structure at index 0:
  keys=['states', 'actions', 'returns_to_go', 'timesteps']

The accepted columns are _CALIBRATION_COLUMNS = ("input_ids", "attention_mask", "text", "messages").

3. The model forward needs named tensors, not input_ids

DecisionTransformerModel.forward(states, actions, rewards, returns_to_go, timesteps, attention_mask, ...).

What already works in our favor

  • The forward already passes arbitrary kwargs through. stage_inputs_capture calls gptq_model.run_input_capture(example, ...), and that is self.model(**example, use_cache=use_cache). A batch of named tensors would reach the model unchanged.
  • Conv1D quantization exists. DT's blocks are GPT-2 blocks (DecisionTransformerGPT2Block → ln_1, attn.c_attn 64x192, attn.c_proj 64x64, ln_2, mlp.c_fc, mlp.c_proj), the same shape as gpt2/codegen, which we already support. SUPPORTS_MODULE_TYPES includes Conv1D.
  • The module tree is mechanical. definitions/gpt2.py maps directly, only the root changes (transformer → encoder):
module_tree = [
    "encoder", "h", "#",
    {"ln_1": ("ln_1:!:norm",), "attn": ("c_attn:0", "c_proj:1"),
     "ln_2": ("ln_2:!:norm",), "mlp": ("c_fc:0", "c_proj:1")},
]
  • The non-block layers are tiny and probably should not be quantized: embed_return (64x1), embed_state (64x8), embed_action (64x3), predict_state (8x64), predict_action.0 (3x64), predict_return (1x64). Only the GPT-2 blocks carry real weight mass.

Proposed plan

  1. Tokenizer-optional load (~20 lines): a definition flag (mirroring require_load_processor) that skips tokenizer instantiation and prepare_dataset tokenization for tensor-calibrated models.
  2. definitions/decision_transformer.py (~80 lines): tree above, no lm_head, heads left in native dtype, modality set to whatever the loader expects for tensor-only models.
  3. Opt-in raw-tensor calibration (~40 lines): a definition flag (suggested calibration_inputs = "tensor_kwargs"), and in calibration.py a branch that accepts Mapping[str, Tensor] when the flag is set, bypassing _tokenize_* and packing. Everything else (batching, move_input_capture_example, capture) already handles tensors.
  4. Tests (~150 lines, CPU): tiny DT (2 layers, hidden 64), quantize 4-bit, compare action_preds against the float reference with a tolerance, assert the six heads stayed native, and assert a text sample still takes the old path for regular models.

Risks and questions

  • Blast radius. Step 3 touches the calibration core that every model uses. Gating it on a definition flag keeps other paths byte-identical, but it is the part that needs review.
  • Should the heads be quantized? They are 1-8 wide; quantizing embed_state (64x8) to 4-bit with group_size 32 is degenerate. Proposal: leave them native and document it, matching how OpenVLA keeps the vision stack native.
  • Naming. calibration_inputs = "token_ids" | "tensor_kwargs" or a richer calibration_builder hook - the hook generalizes better (e.g. π0/GR00T later) but is more API.

Why this is worth it

Offline-RL and robot-policy checkpoints are the main non-text decoder family we cannot touch today. The decoder itself is a plain GPT-2 stack we already quantize; only the tokenizer assumption and the calibration whitelist stand in the way.

Activity

  1. self-assigned this
    on Nov 17, 2026
  2. Qubitium commented on Nov 17, 2026

    @Qubitium
    Collaborator

    @Lumea-art I have not looked at decision transformer. Will do so and get back to you.

  3. Qubitium commented on Nov 17, 2026

    @Qubitium
    Collaborator

    Agent claim: agent-root-4755 is working on this issue now.

  4. Qubitium commented on Nov 17, 2026

    @Qubitium
    Collaborator

    Agent release: agent-root-4755 completed this issue in #4894 (squash-merged to main as 76fd2c7).

    What shipped:

    • DecisionTransformerQModel with the GPT-2 decoder tree under encoder; the 1-8 wide embed_*/predict_* heads stay native and are declared base modules.
    • Definition-scoped require_load_tokenizer = False skips tokenizer loading in both from_pretrained and from_quantized (and tolerates models without the embedding accessors on reload).
    • Definition-scoped calibration_inputs = "tensor_kwargs" validates non-empty Mapping[str, Tensor] rows, one row per batch, and fails closed on non-tensors, 0-D tensors, concat_size, or an empty dataset. Token/text models keep the old path.
    • Registry, registered plan, fusion non-applicability entry, supported-models row, and a flow doc at docs/decision-transformer-calibration.md.

    Tests: the new tests/test_decision_transformer_4755.py is 4 failed, 1 passed on origin/main and 5 passed here; the real-model tests/module_tree/test_decision_transformer_model_tree.py adds 6 passing nodes. Calibration (170), module-tree registry (538 passed, 15 skipped, 3 xfailed), ordering/tags (95), explicit-plan/auto-detect (26), loader (11), and the fusion registry contract all pass.

    AWQ remains explicitly unverified for this definition; only the GPTQ path is claimed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions