transformers
3fe9133c - [exporters] resolve @register_patch paths lazily to avoid eager model imports (#50000)

Commit
29 days ago
[exporters] resolve @register_patch paths lazily to avoid eager model imports (#50000) * [exporters] resolve patch paths lazily in apply_patches, not at decoration time `@register_patch` previously called `_resolve_dotted_path` (which runs `importlib.import_module`) at module-load time, eagerly importing ~37 model modules the moment any exporter file was imported. Since exporter files are imported from `test_export.py`, and `test_export.py` is imported transitively by every `test_modeling_*.py` file via `ModelTesterMixin → ExportTesterMixin`, this caused ~511 test files to record spurious source dependencies on those model modules in `tests_fetcher.py`. Fix: store the dotted-path string in `_PATCHES` instead of the resolved object. `apply_patches` resolves each path just before installing the patch, at which point the model module is already loaded anyway. The `if obj is None` skip logic moves to `apply_patches` via the walrus operator. `patch_attributes` and any direct `patch_attributes(config_patches)` call-sites are unaffected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(test_utils): update test to reflect lazy path resolution in register_patch Path resolution moved from decoration time to apply_patches time, so _PATCHES now stores the raw string — not the resolved object. Update test_register_patch_skips_unresolvable_path to assert the string is stored and that apply_patches silently skips it (still no patch installed, still no exception at import time). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * style: shorten comment to satisfy NC001 (5-line limit) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * style: add PR reference to test comment Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
Author
Parents
Loading