Repository navigation
fix(writer): stop copying remote-code .py files when a native definition owns the config - #6287
Conversation
…ion owns the config Reuse the loader's local_model_loader_for_config() predicate so a definition-owned text export drops the source auto_map and never copies checkpoint Python. Multimodal/processor-bearing ports keep the released metadata required by #6134. The unknown-model remote-code path still copies .py under explicit trust.
ca4e085 to
e7309a0
Compare
|
Review: the core export fix is correct; two non-blocking gaps in the new policy helper. Non-blocking
Verified by running: the minicpm save node is red at |
…native trust - Read modality/require_load_processor from plain class values, falling back to the base definition default when the subclass exposes an instance property. Qwen2.5-VL declares both as properties, so the export metadata helper raised TypeError before its native short-circuit masked it. - Evaluate the definition-owned predicate before the Transformers-native branch so a native type with a package definition still drops checkpoint auto_map and .py files under trust_remote_code=True. Unknown model types keep the trust-controlled positive-control path.
|
Addressed both non-blocking findings in a8ad15c (pushed to
Tests: added |
|
Cross-validation note: this PR also fixes the four
Same mechanism as the minicpm node: the hostile checkpoint ships Command: |
Defect
save()kept the source checkpoint'sauto_mapand copied every source*.pyfile whenever the savedmodel_typewas not registered in Transformers'CONFIG_MAPPING. That predicate ignores GPT-QModel definitions:local_model_loader_for_config()already selects the package config/model for Baichuan, MiniCPM and the other ports, so checkpoint Python can never replace the implementation. The exported Baichuan/MiniCPM checkpoint therefore carried a stalecheckpoint_python.pyand advertisedtrust_remote_code, letting the dropped remote class shadow the native one on reload.Reproduced at
89dbcf91(CPU):Predicate reused
local_model_loader_for_config()— the same definition-selection predicate used byload_model_config()andresolve_trust_remote_code(). A returned loader means the package owns the config/model, so the export must dropauto_mapand must not copy checkpoint Python. The existing #6134 carve-out is retained for self-describing multimodal/processor-bearing ports (modality/require_load_processor), which keep the released metadata.Changes
gptqmodel/models/writer.py_remote_code_export_preserved()/_definition_remote_code_export()around the reused predicate._preserve_remote_code_config()now dropsauto_mapfor definition-owned text exports even whentrust_remote_code=True._save_model_configs_without_weights()returns the policy;save_quantized()uses it instead ofself.trust_remote_codefor the extra.pycopy.save_quantized_embeddings()uses the same policy and excludes.pyfrom_copy_missing_checkpoint_files()when remote code is not exported.tests/test_config_only_export.pytest_native_definition_save_drops_checkpoint_python_even_with_trust(negative).test_unknown_remote_code_save_still_copies_checkpoint_python(positive control).Red/green
Red at HEAD for the new negative node (same intended reason as the public repro):
Green with the fix:
No merge; draft only.