[BUG]: GeminiPlugin cannot load a sharded model checkpoint: `GeminiDDP.named_parameters()` rejects `remove_duplicate`
Is there an existing issue for this bug?
- [x] I have searched the existing issues
The bug has not been fixed in the latest main branch
- [x] I have checked the latest main branch
Do you feel comfortable sharing a concise (minimal) script that reproduces the error? :)
Yes, I will share a minimal reproducible script.
🐛 Describe the bug
booster.load_model fails for any sharded model checkpoint with GeminiPlugin:
File "colossalai/booster/plugin/gemini_plugin.py", line 236, in load_sharded_model
return super().load_sharded_model(
File "colossalai/checkpoint_io/general_checkpoint_io.py", line 312, in load_sharded_model
for name, parameter in model.named_parameters(remove_duplicate=False):
TypeError: GeminiDDP.named_parameters() got an unexpected keyword argument 'remove_duplicate'
GeneralCheckpointIO.load_sharded_model resolves tied parameters with model.named_parameters(remove_duplicate=False) when strict=True (the default)
(general_checkpoint_io.py#L312). GeminiCheckpointIO delegates to it, but GeminiDDP overrides named_parameters(self, prefix="", recurse=True) without that argument
(gemini_ddp.py#L227).
The call was added in fde31efe ("Add version-dispatched Transformers 5.17 ShardFormer compatibility", #6474). A fix is to forward the keyword: def named_parameters(self, prefix="", recurse=True, remove_duplicate=True): return self.module.named_parameters(prefix, recurse, remove_duplicate), and the same for named_buffers if it is ever called that way.
Reproduction (1 GPU):
# torchrun --nproc_per_node=1 gemini_load.py
import tempfile
from torch import nn
import colossalai
from colossalai.booster import Booster
from colossalai.booster.plugin import GeminiPlugin
from colossalai.nn.optimizer import HybridAdam
colossalai.launch_from_torch()
def build():
model = nn.Sequential(nn.Linear(8, 8), nn.Linear(8, 8))
booster = Booster(plugin=GeminiPlugin(precision="bf16"))
model, *_ = booster.boost(model, HybridAdam(model.parameters()))
return booster, model
booster, model = build()
with tempfile.TemporaryDirectory() as ckpt:
booster.save_model(model, ckpt, shard=True)
booster, model = build()
booster.load_model(model, ckpt)
print("loaded")
It fails with the error above instead of printing loaded.
Environment
- ColossalAI: main at d414d565
- PyTorch 2.13.0+cu130, CUDA 13.0, transformers 5.17.0, Python 3.10.12
- 1× NVIDIA H20, driver 595.71.05