|
| 1 | +# Sarvam Examples |
| 2 | + |
| 3 | +This directory contains example scripts for Sarvam language models. |
| 4 | + |
| 5 | +Sarvam models use a Mixture of Experts (MoE) architecture with QKV layernorm and Grouped Query Attention (GQA). |
| 6 | + |
| 7 | +| Model | HF ID | Architecture | Params | |
| 8 | +|---|---|---|---| |
| 9 | +| Sarvam 30B | `sarvamai/sarvam-30b` | MoE (128 experts, top-6) | 30B total, 3B active | |
| 10 | +| Sarvam 105B | `sarvamai/sarvam-105b` | MoE (128 experts, top-8) | 105B total, 10.3B active | |
| 11 | + |
| 12 | +## Workspace Configuration |
| 13 | + |
| 14 | +All scripts use a `WORKSPACE` environment variable for the base directory. Default: `/workspace`. |
| 15 | + |
| 16 | +```bash |
| 17 | +export WORKSPACE=/your/custom/path |
| 18 | +``` |
| 19 | + |
| 20 | +Directory structure: |
| 21 | +- `${WORKSPACE}/models/` - Converted checkpoints |
| 22 | +- `${WORKSPACE}/results/` - Training outputs |
| 23 | + |
| 24 | +## Checkpoint Conversion |
| 25 | + |
| 26 | +See [conversion.sh](conversion.sh) for checkpoint conversion examples. |
| 27 | + |
| 28 | +### Import HF → Megatron |
| 29 | + |
| 30 | +```bash |
| 31 | +python examples/conversion/convert_checkpoints.py import \ |
| 32 | + --hf-model sarvamai/sarvam-30b \ |
| 33 | + --megatron-path ${WORKSPACE}/models/sarvam-30b \ |
| 34 | + --trust-remote-code |
| 35 | +``` |
| 36 | + |
| 37 | +### Export Megatron → HF |
| 38 | + |
| 39 | +```bash |
| 40 | +python examples/conversion/convert_checkpoints.py export \ |
| 41 | + --hf-model sarvamai/sarvam-30b \ |
| 42 | + --megatron-path ${WORKSPACE}/models/sarvam-30b/iter_0000000 \ |
| 43 | + --hf-path ${WORKSPACE}/models/sarvam-30b-hf-export |
| 44 | +``` |
| 45 | + |
| 46 | +### Round-trip Validation |
| 47 | + |
| 48 | +```bash |
| 49 | +python -m torch.distributed.run --nproc_per_node=8 \ |
| 50 | + examples/conversion/hf_megatron_roundtrip_multi_gpu.py \ |
| 51 | + --hf-model-id sarvamai/sarvam-30b \ |
| 52 | + --megatron-load-path ${WORKSPACE}/models/sarvam-30b/iter_0000000 \ |
| 53 | + --tp 2 --pp 2 --ep 2 \ |
| 54 | + --trust-remote-code |
| 55 | +``` |
| 56 | + |
| 57 | +## Inference |
| 58 | + |
| 59 | +See [inference.sh](inference.sh) for text generation with: |
| 60 | +- Hugging Face checkpoint (`sarvamai/sarvam-30b`) |
| 61 | +- Imported Megatron checkpoint (after [conversion.sh](conversion.sh) import) |
| 62 | +- Exported HF checkpoint (after conversion export) |
| 63 | + |
| 64 | +The default parallelism for 8 GPUs is `--tp 2 --pp 1 --ep 4 --etp 1`. |
| 65 | +TP×PP×EP must equal `--nproc_per_node`. |
| 66 | + |
| 67 | +> **Note**: `sarvamai/sarvam-30b` is a base pretrained model published in float32. |
| 68 | +> The Bridge conversion is correct (verified by matching outputs between HF and Megatron checkpoints). |
| 69 | +> For coherent text generation, use an instruction-tuned variant if available. |
0 commit comments