-
Notifications
You must be signed in to change notification settings - Fork 27.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not use deprecated SourceFileLoader.load_module()
in dynamic module loading
#30370
Conversation
cc @ydshieh |
Hi @XuehaiPan Thank you for opening this PR ❤️ . Overall LGTM, but there is one test failing
Could you check if it pass on |
Hi @ydshieh, I have fixed the test error. |
Thanks! CI is green. I will check ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the iteration!
6985bee
to
c9ea68f
Compare
Ah, thank you for the quick action ❤️ . I was thinking probably better not to bother you further |
c9ea68f
to
24cde2d
Compare
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
# insert it into sys.modules before any loading begins | ||
sys.modules[name] = module | ||
# reload in both cases | ||
module_spec.loader.exec_module(module) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@XuehaiPan why do you call exec_module
in both cases here?
it has the effect of reloading code definitions from disk for every model instantiation, which breaks monkey-patches applied onto trust_remote_code models (i.e. liger-kernel, etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think here we did this to match the previous code block, where
module = importlib.machinery.SourceFileLoader(name, module_path).load_module()
was always executed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@XuehaiPan why do you call exec_module in both cases here?
This intentional. The module instance will be inserted into sys.module
during initialization, whether it is executed or not (partially initializaed). Maybe we can add a module.__initialized
indicator to ensure the module file is executed only once. I will submit a PR to resolve this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this PR do?
Remove deprecated
SourceFileLoader.load_module()
in dynamic module loading. Replace it withexec_module()
.https://github.com/python/cpython/blob/e3671ead9419c7afab6a4e501ade86bc9bc10950/Lib/importlib/_bootstrap_external.py#L1166-L1176
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.