> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/automodel/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/automodel/_mcp/server.

# gpt2

> Pretrain gpt2 with NeMo AutoModel using a documented checkpoint, runnable recipe, setup guidance, model reference details, and links to the pretraining guide.

[GPT-2](https://huggingface.co/openai-community/gpt2) is OpenAI's foundational decoder-only transformer. NeMo AutoModel uses it as a baseline for the Megatron pretraining smoke test and tutorials - its small footprint makes it a convenient target to validate data pipelines, distributed configs, and logging without needing large compute.

Set up NeMo AutoModel with the [latest container](https://catalog.ngc.nvidia.com/orgs/nvidia/containers/nemo-automodel) or follow the [installation instructions](/get-started/installation).

## Pretrain gpt2

From the repository root, run:

```bash
uv run automodel --nproc-per-node=8 examples/llm_pretrain/megatron_pretrain_gpt2.yaml
```

## Choose a Workflow

| Goal                                                   | Start Here                                                                                                                                 |
| ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ |
| Megatron pretraining smoke test - GPT-2 on FineWeb-Edu | Use [megatron\_pretrain\_gpt2.yaml](https://github.com/NVIDIA-NeMo/Automodel/blob/main/examples/llm_pretrain/megatron_pretrain_gpt2.yaml). |

## Model Reference

### Model Architecture

| Property                  | Value                                                       |
| ------------------------- | ----------------------------------------------------------- |
| Task                      | Text Generation (pretraining baseline)                      |
| Architecture              | `GPT2LMHeadModel`                                           |
| Parameters                | 124M                                                        |
| Hugging Face Organization | [openai-community](https://huggingface.co/openai-community) |

### Available Models

| Model | HF ID                                                                   |
| ----- | ----------------------------------------------------------------------- |
| GPT-2 | [`openai-community/gpt2`](https://huggingface.co/openai-community/gpt2) |

## Related Resources

* [LLM Pretraining Guide](/recipes-e2e-examples/pretraining)