Skip to content

Fix compression_config dropped when loading compressed models from JSON config#333

Merged
yghstill merged 1 commit into
Tencent:mainfrom
SuperMarioYL:fix-json-compression-config
Jun 7, 2026
Merged

Fix compression_config dropped when loading compressed models from JSON config#333
yghstill merged 1 commit into
Tencent:mainfrom
SuperMarioYL:fix-json-compression-config

Conversation

@SuperMarioYL
Copy link
Copy Markdown
Contributor

Summary

parse_json_full_config() parses the compression_config section into a local
comp_config, but the returned FullConfig(...) omits the compression_config=
argument. Because FullConfig.compression_config defaults to None, every config
loaded through this function comes back without any compression metadata,
silently discarding the parsing work.

This is the path used when reloading a previously compressed model:

# angelslim/engine.py (prepare_model)
slim_config = parse_json_full_config(slim_config_path)   # reads angelslim_config.json
...
self.slim_model.from_pretrained(
    ...,
    compress_config=slim_config.compression_config,      # always None before this fix
)

So the compressed-model save → load round-trip loses the compression
configuration. The YAML parser (SlimConfigParser._get_configs) already passes
compression_config correctly — this change brings the JSON parser in line with it.

Changes

  • Pass compression_config=comp_config to FullConfig(...) in parse_json_full_config.
  • Remove a verbatim-duplicated calibrate/transform parsing block in the same
    function (the second copy recomputed identical values).
  • Raise a descriptive ValueError for a missing required JSON section
    (model_config / compression_config) instead of a bare KeyError, matching
    the validation style of the YAML parser.
  • Add CPU-only regression tests (tests/test_config_parser.py) covering the
    round-trip and the missing-section path. They need neither a GPU nor model
    weights.

Testing

python -m pytest tests/test_config_parser.py -q

pre-commit run --all-files passes (black / isort / flake8) on the changed files.

parse_json_full_config built the compression config but omitted
compression_config= from the returned FullConfig, so models loaded via
Engine.prepare_model (which reads angelslim_config.json) always received
compression_config=None. As a result from_pretrained was called with
compress_config=None, breaking the compressed-model save/load round-trip.
The YAML parser already passes compression_config correctly; this aligns
the JSON parser with it.

Also remove a verbatim-duplicated calibrate/transform parsing block and
raise a descriptive error for missing required JSON sections. Add CPU-only
regression tests covering the round-trip and the missing-section path.

Signed-off-by: supermario_leo <leo.stack@outlook.com>
@yghstill yghstill merged commit 5de42f8 into Tencent:main Jun 7, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants