-
Notifications
You must be signed in to change notification settings - Fork 108
Clean up traces for symbolic values caching #2662
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
base: main
Are you sure you want to change the base?
Changes from 8 commits
e7c8bc9
28408f7
cb31f7f
db83930
3986848
94d9b81
5363067
3ace3b5
129e9d0
06ca4df
303fb68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -244,20 +244,20 @@ def get_backed_value(s): | |
| return tuple(map(get_backed_value, vals)) | ||
|
|
||
|
|
||
| def get_proxy_inputs_from_node(node: torch.fx.Node) -> tuple[tuple, dict]: | ||
| def get_proxy_inputs_from_node(node: torch.fx.Node, tracectx) -> tuple[tuple, dict]: | ||
| """Creates proxy inputs from a torch.fx.Node for use with Thunder. | ||
|
|
||
| This function generates proxy inputs for a given torch.fx.Node | ||
|
|
||
| Args: | ||
| node (torch.fx.Node): The FX graph node to create proxy inputs for. | ||
| tracectx (TraceCtx): The trace context to use to generate proxy inputs. | ||
| """ | ||
| import thunder | ||
| from thunder.core.trace import TraceCtx | ||
| from thunder.core.proxies import proxy | ||
|
|
||
| # We need to be under trace context to generate proxies. | ||
| with thunder.core.trace.tracectx(TraceCtx()): | ||
| with thunder.core.trace.tracectx(tracectx): | ||
|
|
||
| def make_input_proxy(arg_node): | ||
| # This is a Node in the graph representing a Tensor or tuple of Tensors or | ||
|
|
@@ -365,8 +365,10 @@ def _run_with_cache_info(): | |
| cache_info["default_dtype"] = torch.get_default_dtype() | ||
| cache_info["default_device"] = torch.get_default_device() | ||
|
|
||
| tracectx = TraceCtx() | ||
|
|
||
| try: | ||
| proxy_args, proxy_kwargs = get_proxy_inputs_from_node(node) | ||
| proxy_args, proxy_kwargs = get_proxy_inputs_from_node(node, tracectx) | ||
| except Exception as e: | ||
| return False, SplitReason( | ||
| SplitReasonType.EXCEPTION_PROXY_THUNDER_OP, | ||
|
|
@@ -380,7 +382,7 @@ def _run_with_cache_info(): | |
| else thunder_symbol | ||
| ) | ||
| # We need to be under trace context to generate proxies. | ||
| with thunder.core.trace.tracectx(TraceCtx()): | ||
| with thunder.core.trace.tracectx(tracectx): | ||
| try: | ||
| function_to_run(*proxy_args, **proxy_kwargs) | ||
|
Comment on lines
-399
to
402
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the source of all of my woes. This pattern implicitly binds the provided |
||
| except Exception as e: | ||
|
|
@@ -463,6 +465,7 @@ def is_node_supported_by_thunder( | |
| """ | ||
| Determine whether thunder can execute the operation described by this node. | ||
| """ | ||
| from thunder.core.trace import TraceCtx | ||
| # Docs from the torch.fx.Node - https://pytorch.org/docs/stable/fx.html#torch.fx.Node | ||
| # Each Node has a function specified by its op property | ||
| # Below are the details for the ones this function is interested in - | ||
|
|
@@ -534,7 +537,7 @@ def is_node_supported_by_thunder( | |
| if torchctx.has_method(node.target): | ||
| # `torchctx.get_method` requires args and kwargs to resolve which overload of the method is picked. | ||
| try: | ||
| args, kwargs = get_proxy_inputs_from_node(node) | ||
| args, kwargs = get_proxy_inputs_from_node(node, TraceCtx()) | ||
| except Exception as e: | ||
| return False, SplitReason( | ||
| SplitReasonType.EXCEPTION_PROXY_THUNDER_OP, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.