Checkpoint conversion: The size of tensor a (32768) must match the size of tensor b (8192) at non-singleton dimension 0
Describe the bug
For Llama mistral checkpoint conversion
Using TP=1 will result in a successful conversion. But TP=4 failed with
The size of tensor a (32768) must match the size of tensor b (8192) at non-singleton dimension 0
Steps/Code to reproduce bug
If anyone encounter the following issue, change TP=4 to TP=1.
python tools/checkpoint/convert.py \
--bf16 \
--model-type GPT \
--loader llama_mistral \
--saver core \
--target-tensor-parallel-size 4 \
--checkpoint-type hf \
--load-dir /root/.cache/huggingface/hub/models--mistralai--Mistral-7B-v0.3/snapshots/caa1feb0e54d415e2df31207e5f4e273e33509b1 \
--save-dir ./converted_mistral \
--tokenizer-model /root/.cache/huggingface/hub/models--mistralai--Mistral-7B-v0.3/snapshots/caa1feb0e54d415e2df31207e5f4e273e33509b1 \
--model-size mistral
building GPT model ...
/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/module/base.py:1093: UserWarning: To guarantee overlapping TP and SP collectives with the backwardGEMMs, set environment variable CUDA_DEVICE_MAX_CONNECTIONS = 1
warnings.warn(
Process Process-1:
Traceback (most recent call last):
File "/usr/lib/python3.12/multiprocessing/process.py", line 314, in _bootstrap
self.run()
File "/usr/lib/python3.12/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/lustre/fsw/coreai_prod_infbench/faradawny/Megatron-LM/tools/checkpoint/saver_core.py", line 71, in save_checkpoint
raise e
File "/lustre/fsw/coreai_prod_infbench/faradawny/Megatron-LM/tools/checkpoint/saver_core.py", line 69, in save_checkpoint
saver.save()
File "/lustre/fsw/coreai_prod_infbench/faradawny/Megatron-LM/tools/checkpoint/saver_base.py", line 329, in save
self.receive_model()
File "/lustre/fsw/coreai_prod_infbench/faradawny/Megatron-LM/tools/checkpoint/saver_core.py", line 61, in receive_model
self.receive_lm(schema)
File "/lustre/fsw/coreai_prod_infbench/faradawny/Megatron-LM/tools/checkpoint/saver_base.py", line 420, in receive_lm
schema.set("embeddings", model, {
File "/lustre/fsw/coreai_prod_infbench/faradawny/Megatron-LM/tools/checkpoint/schema_base.py", line 82, in set
self._set(self[key], model, params)
File "/lustre/fsw/coreai_prod_infbench/faradawny/Megatron-LM/tools/checkpoint/schema_base.py", line 79, in _set
cls._set_deep_tensor(model, m, params[k])
File "/lustre/fsw/coreai_prod_infbench/faradawny/Megatron-LM/tools/checkpoint/schema_base.py", line 50, in _set_deep_tensor
dst.copy_(src)
RuntimeError: The size of tensor a (32768) must match the size of tensor b (8192) at non-singleton dimension 0
Expected behavior
A clear and concise description of what you expected to happen.
Additional context
Add any other context about the problem here.
you can use Megatron-Bridge Repo, multi-card ref: https://github.com/NVIDIA-NeMo/Megatron-Bridge/blob/main/examples/conversion/hf_megatron_roundtrip_multi_gpu.py
PR-fix is ready: https://github.com/NVIDIA/Megatron-LM/pull/4058
PR was merged.