Skip to content
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

check if self.sym is ad hoc before querying the existence of self.sym.module #1544

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions thunder/core/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,18 +619,23 @@ def import_ctx(self):
# NOTE If the call ctx was specified directly, then no import is needed to call the function
import_ctx = {}
else:
from thunder.extend import AdHocExecutor

# BoundSymbols of Symbols without Python implementations (either because they
# have Python implementations or defined call ctxs) are assumed to need
# a module import to run properly
assert self.sym.module is not None # TODO: Is this a valid assumption?
module_name = self.sym.module.__name__
import_ctx = {module_name: self.sym.module}

# TODO Include the other modules on the path?
# Also includes the root module of this (potential) submodule
if "." in module_name:
root_name = module_name.split(".")[0]
import_ctx[root_name] = sys.modules[root_name]
if isinstance(self.sym.executor, AdHocExecutor):
import_ctx = {}
else:
assert self.sym.module is not None # TODO: Is this a valid assumption?
module_name = self.sym.module.__name__
import_ctx = {module_name: self.sym.module}

# TODO Include the other modules on the path?
# Also includes the root module of this (potential) submodule
if "." in module_name:
root_name = module_name.split(".")[0]
import_ctx[root_name] = sys.modules[root_name]

self._import_ctx.update(import_ctx)
return self._import_ctx
Expand Down
Loading