megatron-hf-converter — Claude Code skill guide

Convert HuggingFace and Megatron-LM checkpoints with numerical equivalence validation.

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/BirgerMoell/megatron-hf-converter --skill megatron-hf-converter-claude-code-skill-guide
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: megatron-hf-converter — Claude Code skill guide
Source: https://github.com/BirgerMoell/megatron-hf-converter/tree/main
Command: npx skills add https://github.com/BirgerMoell/megatron-hf-converter --skill megatron-hf-converter-claude-code-skill-guide

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, transformers, safetensors.

What problem does it solve?

This Skill automates the conversion of large language model checkpoints between HuggingFace and Megatron-LM formats and validates numerical equivalence after conversion.

Core Features & Use Cases

  • HF → Megatron: Convert HuggingFace models to Megatron-LM format via Megatron-Bridge, enabling scalable training pipelines.
  • Megatron → HF: Export Megatron checkpoints back to HuggingFace format, with tokenizer handling options and optional patching.
  • Round-trip validation: Validate weight mappings and inference consistency to catch mapping errors early.
  • Tokenizer patching: Adjust tokenizers post-export to align with architecture configs when needed.

Quick Start

Run hf_to_megatron.sh with your HF model and a target Megatron path to start the conversion.

Frequently Asked Questions about megatron-hf-converter — Claude Code skill guide

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I convert HuggingFace checkpoints to Megatron-LM format for distributed training?

To convert HuggingFace checkpoints to Megatron-LM format, run hf_to_megatron.sh with your HF model path and target Megatron path. This automates the HF→Megatron workflow via Megatron-Bridge, enabling scalable training pipelines.

Can I export Megatron-LM checkpoints back to HuggingFace format for inference?

Yes, you can export Megatron checkpoints back to HuggingFace format for inference. The conversion process includes tokenizer handling options and optional patching to align the exported model with the target architecture configuration.

How do I validate weight equivalence after converting a model between HuggingFace and Megatron?

You validate weight equivalence after model conversion by running round-trip validation. This checks weight mappings and inference consistency to catch mapping errors early and ensures numerical equivalence between the converted checkpoints.

Do I need Megatron-Bridge to convert checkpoints between HuggingFace and Megatron-LM?

Yes, you need Megatron-Bridge to convert checkpoints between HuggingFace and Megatron-LM. The Skill requires Megatron-Bridge along with PyTorch, transformers, and safetensors to automate the conversion and validate numerical equivalence.

What's the best way to handle tokenizer mismatches when exporting Megatron checkpoints to HuggingFace?

The best way to handle tokenizer mismatches during Megatron to HuggingFace export is to use tokenizer patching. This adjusts tokenizers post-export to align with the target architecture configuration when needed.