feat(tools): add HF model normalization utility - #2073
Open
caixianzhang wants to merge 6 commits into
Open
Conversation
jayhenry
approved these changes
Sep 7, 2026
…version Add --base-model-dir to repack and to-fp8. After conversion, copy the directory's generation_config.json verbatim (overwriting any existing one, logged) and rewrite the first Copyright line of its LICENSE to the fixed "Copyright 2025-2026 Shanghai AI Laboratory" string, leaving the license body untouched. Missing files are skipped; a None directory is a no-op so existing behavior is preserved. A --base-model-dir generation_config takes precedence over --generation-config. Wire BASE_MODEL_DIR through run_glm52.sh, document the option and output shape, and add focused tests for the rewrite and apply logic. Verified end-to-end in the glm5-2 job: BF16 (353 shards) and FP8 (177 shards, 59044 scale_inv matching the reference) both produced rewritten LICENSE and overridden generation_config.
--base-model-dir supersedes --generation-config: a directory containing only generation_config.json reproduces the old behavior and additionally stamps a rewritten LICENSE. Removing the single-file option leaves one release-asset entry point and no precedence rules to document. The PR is not merged upstream, so there is no compatibility surface.
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.
Summary
xtuner.tools.model_normalizeCLI for HF repack and FP8 conversion--base-model-dirto stamp a user-suppliedLICENSE(Copyright line rewritten toCopyright 2025-2026 Shanghai AI Laboratory) andgeneration_config.jsoninto the product after conversion (supersedes a single-file--generation-configoption, which was dropped before merge)Scope
This PR intentionally provides conversion/repacking only. It does not run full-model validation, SHA256 scans, inference services, or Hub uploads.
--base-model-dir(release assets)Both
repackandto-fp8accept--base-model-dir <dir>, applied after conversion:generation_config.json(if present) is copied verbatim into the output, overwriting any existing file (overwrite is logged).LICENSE(if present) is copied with its first Copyright line rewritten to the fixedCopyright 2025-2026 Shanghai AI Laboratory; the license body is left untouched. An existing outputLICENSEis overwritten (logged). No Copyright line -> file written unchanged with a warning.generation_config.jsonremains in the output as-is.Validation
ruff check xtuner/tools/model_normalize tests/tools/test_model_normalize_cli.pyPYTHONPATH=. pytest -q --confcutdir=tests/tools tests/tools/test_model_normalize_cli.py(base-model-dir/license tests pass; repack test skipped whensafetensorsis unavailable)bash xtuner/tools/model_normalize/run_model_normalize.sh --helpglm5-2-8gpu-99022910-cfcd2job (8x H200):model.safetensors.index.jsonpresent,LICENSECopyright rewritten,generation_config.jsonoverridden — rc=0.*_scale_invtensors matching the reference,LICENSE/generation_config.jsonapplied — rc=0.dev_notes/workflow/pr2073_base_model_dir_verification.md.run_glm52.shusageThe GLM-5.2 example accepts one positional argument:
It does not define other positional arguments; extra arguments are ignored.
Environment variables:
SOURCE_DIROUTPUT_ROOTSHARD_SIZE_GB4REFERENCE_DIRMAX_SAVE_WORKERS4BASE_MODEL_DIRLICENSEandgeneration_config.jsonto stamp into the productBF16 example:
FP8 example:
The output directories are fixed relative to
OUTPUT_ROOT: