fix(moe/deepseek): create the output directory before writing config.json (#697) - #701
Open
Anai-Guo wants to merge 1 commit into
Open
fix(moe/deepseek): create the output directory before writing config.json (#697)#701Anai-Guo wants to merge 1 commit into
Anai-Guo wants to merge 1 commit into
Conversation
…json DeepseekMoE.write_model() opens out_path/config.json directly, while the Mixtral/Qwen/Qwen3 writers persist their config through PretrainedConfig.save_pretrained(), which does os.makedirs(..., exist_ok=True). Nothing in mergekit.scripts.moe.build() creates out_path beforehand, so a Deepseek MoE merge into a not-yet-existing output directory dies with FileNotFoundError before any weights are written. Create the directory first, matching what the other output architectures get for free from save_pretrained().
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #697.
Problem
DeepseekMoE.write_model()writes the output config with a plainopen():Nothing creates
out_pathbefore that point:mergekit.scripts.moe.build()callsout_arch.write_model(out_path, ...)directly — it never creates the directory itself.initialize_io()(which constructs theTensorWriterthat does create it) runs after theconfig.jsonwrite.So a Deepseek MoE merge whose
out_pathdoes not already exist dies withFileNotFoundErrorbefore a single weight is written.The other output architectures don't hit this because they persist their config through
transformers:mergekit/moe/mixtral.py:118out_cfg.save_pretrained(out_path)mergekit/moe/qwen.py:113out_cfg.save_pretrained(out_path)mergekit/moe/qwen3.py:93out_cfg.save_pretrained(out_path)mergekit/moe/deepseek.py:121open(...)PretrainedConfig.save_pretrained()starts withos.makedirs(save_directory, exist_ok=True), so Mixtral/Qwen/Qwen3 get the directory for free. Deepseek builds a plaindict(it needs theauto_mapremote-code keys), so it can't usesave_pretrainedand has to do this explicitly.Fix
One line, immediately before the write:
exist_ok=Truemakes it a no-op for the already-common case where the directory exists, so behaviour is unchanged for every currently-working merge.Notes
write_model()needs real source checkpoints to run end to end, andtests/has no MoE coverage to hang a unit test off. The change is a strict superset of the previous behaviour.black 25.1.0andisort 6.0.0(withpyproject.tomlsettings andmergekitas first-party) both report the file clean.🤖 Generated with Claude Code
Note
Low Risk
Single-line filesystem guard before config write; no change to merge logic or weight handling.
Overview
DeepSeek MoE merges no longer fail when the output path does not exist yet.
DeepseekMoE.write_model()writesconfig.jsonwith a directopen()beforeinitialize_io()runs, unlike Mixtral/Qwen paths that usesave_pretrained()(which creates the directory). The change addsos.makedirs(out_path, exist_ok=True)immediately before that write so behavior matches the other MoE writers without affecting merges that already use an existing directory.Reviewed by Cursor Bugbot for commit 8764ddd. Bugbot is set up for automated code reviews on this repo. Configure here.