@@ -32,6 +32,36 @@ uv run python examples/conversion/hf_megatron_roundtrip.py \
3232This utility currently targets decoder-only checkpoints with a top-level
3333` num_hidden_layers ` config field and tensor names containing ` layers.<index> ` .
3434
35+ ### ` repair_hf_embedding_rows.py ` - Repair Near-Zero Input Embedding Rows
36+
37+ Creates a repaired copy of a local Hugging Face safetensors checkpoint by
38+ rewriting diagnosed near-zero input embedding rows. It is intended for one-off
39+ continued-pretraining cleanup when rare token IDs in the base checkpoint can
40+ produce extreme embedding gradients.
41+
42+ The script scans the input embedding row norms, replaces rows whose L2 norm is
43+ non-finite or at/below ` --min-norm ` with the matching ` lm_head.weight ` direction
44+ scaled to the RMS norm of healthy input rows, and writes a manifest with the
45+ affected token IDs. It preserves the HF checkpoint layout and safetensors index.
46+
47+ ``` bash
48+ uv run python examples/conversion/repair_hf_embedding_rows.py \
49+ --input-hf-path /models/NVIDIA-Nemotron-3-Nano-4B-BF16 \
50+ --output-hf-path /models/NVIDIA-Nemotron-3-Nano-4B-BF16-repaired \
51+ --min-norm 1.0e-4 \
52+ --max-rows 256
53+
54+ # Diagnose only, without writing an output checkpoint
55+ uv run python examples/conversion/repair_hf_embedding_rows.py \
56+ --input-hf-path /models/NVIDIA-Nemotron-3-Nano-4B-BF16 \
57+ --dry-run
58+ ```
59+
60+ By default the tool infers common tensor names such as
61+ ` backbone.embeddings.weight ` and ` lm_head.weight ` . Use
62+ ` --input-embedding-name ` and ` --output-embedding-name ` if a checkpoint uses
63+ different names.
64+
3565### 1. ` hf_megatron_roundtrip.py ` - Two-Way Model Conversion
3666
3767Demonstrates round-trip conversion between HuggingFace and Megatron-LM model formats.
0 commit comments