Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 8 min read How-to hardMaster

Train your first Decision Transformer

Decision Transformers recast reinforcement learning as conditional sequence modeling: a GPT-2 model takes the last K timesteps of return-to-go, state and action tokens and autoregressively predicts actions that achieve a desired return. This walkthrough trains an offline Decision Transformer from scratch on the HalfCheetah expert dataset from the Hugging Face hub. A custom data collator normalizes states, computes returns-to-go, scales rewards by 1000, pads sequences and samples trajectories by length. A subclassed model adds an MSE action loss so the standard transformers Trainer can be used, and training takes about 40 minutes in Colab versus roughly 3 hours in the original paper.

Assumes: reinforcement learning basicstransformer architecturePyTorchHugging Face transformers Trainer

Related posts

  • Introducing Decision Transformers on Hugging Face 🤗

    Hugging Face mediumAdept

    Decision Transformer, an offline reinforcement learning method that recasts RL as return-conditioned sequence modeling, is now part of the 🤗 transformers library, with nine pretrained checkpoints for Gym continuous-control tasks (Hopper, Walker2D, HalfCheetah). Instead of fitting a value function, a GPT-2 model takes the last K timesteps of return-to-go, state and action tokens and autoregressively predicts actions that reach a desired return. Code covers loading the model, padding and masking a 20-step context window, normalizing states with the mean and standard deviation from each model card, and running an evaluation loop. Setting the target return directly controls how well the resulting policy performs.

  • Jack of All Trades, Master of Some, a Multi-Purpose Transformer Agent

    Hugging Face hardMaster

    JAT (Jack of All Trades) is an open reproduction of DeepMind's Gato: a single GPT-Neo-based Transformer trained by behavioral cloning on a new dataset of expert trajectories from Atari, BabyAI, Meta-World and MuJoCo, plus text and image-caption data. It interleaves observation/reward and action embeddings, using modality-specific encoders (CNN for images, linear layers for continuous and discrete values, ViT for images, GPT-2 tokenization for text), with MSE or cross-entropy losses per modality. Across 157 tasks it averages 65.8% of expert performance, ranging from 14.1% on Atari 57 to 99.0% on BabyAI, with only rudimentary NLP and CV ability. Adding observation prediction as an auxiliary loss helps when weighted around κ=0.005 and hurts at 0.5, and the expert agents, dataset and model are all released on the Hugging Face Hub.

  • Decision Models in Hugging Face

    Hugging Face mediumAdept

    Decision models take a state plus a set of typed questions with predefined answers and return structured decisions with probabilities instead of generating text, avoiding schema violations and autoregressive decoding overhead. Three primitives cover most cases: choice (softmax over options), score (expected value over an ordered scale), and noul (a Bernoulli probability for yes/no). Choice and score also report a confidence value that normalizes the top probability against a uniform distribution. The post compares the approach with fixed-label and zero-shot NLI classification and shows usage through a new transformers "decision" pipeline intended to give these models a common interface.

  • Turning Database Grading into RL Rewards: Post-Training Agents with ThinkingBox

    Hugging Face hardMaster

    Executable checks on terminal database state, originally built to grade agents in ThinkingBox-Bench, double as binary RL rewards for post-training tool-using agents. Fine-tuning Qwen3.8-27B with token-mean GRPO for 50 steps on 187 out-of-distribution tasks raised pass@1 from 51.70% to 60.78% and tasks solved on all 20 attempts from 38 to 107, while pass@20 coverage dipped slightly, consistent with sharpening. The key lever is offline policy-relative difficulty: candidate tasks are probed against the base policy, a Jeffreys Beta posterior estimates success probability, and only tasks likely to yield mixed reward groups (non-zero GRPO advantage) are kept. Cost per dependable task fell from $24.36 to $8.00, approaching frontier models.

  • User foundation models for Grab

    Grab Engineering hardMaster

    Grab built a transformer-based user foundation model that jointly learns from tabular user attributes and time-series clickstream data to produce general-purpose user embeddings, replacing siloed hand-engineered features. A universal key:value tokenisation with custom positional embeddings and attention masks treats tabular columns as an unordered set and events as an ordered sequence. Modality-specific adapters (pre-trained language models for text, embedding layers for IDs, custom encoders for locations and numbers) feed an alignment layer before the transformer. Pre-training is unsupervised, combining masked token reconstruction with next-action prediction across verticals, so the embeddings serve many downstream tasks such as ads, fraud detection and churn prediction, or the model can be fine-tuned directly.

The quest for software engineering knowledge.

Look:
Layout: