Skip to content

Conversation

ydwu4
Copy link
Contributor

@ydwu4 ydwu4 commented Oct 20, 2024

Copy link

pytorch-bot bot commented Oct 20, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/138428

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (3 Unrelated Failures)

As of commit 0a8e9df with merge base 8e27833 (image):

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

ydwu4 added 3 commits October 20, 2024 11:24
…s take example_value"

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec

[ghstack-poisoned]
…s take example_value"

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec

[ghstack-poisoned]
…s take example_value"

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec

[ghstack-poisoned]
example_value = wrap_to_fake_tensor_and_record(
tensor_value,
tx=self.tx,
is_tensor=False,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_tensor is dermined by whether target_cls in (TensorVariable, TensorWithTFOverrideVariable). NumpyNdarraryVaraible is not in them so is_tensor = False. This PR keeps this behavior unchanged and only do code-refactoring.

# TODO: Maybe the tensor-ification should be built into the source,
# rather than by special pattern match
example_value = wrap_to_fake_tensor_and_record(
wrapped_value, tx=self.tx, is_tensor=False, source=self.get_source()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here for is_tensor=False

options.update({"raw_value": value})

example_value = wrap_to_fake_tensor_and_record(
wrapped_value, tx=self.tx, is_tensor=False, source=self.get_source()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

# the subgraph.
# See NOTE [HigherOrderOperator tracing design] for more details.

example_value = wrap_to_fake_tensor_and_record(
Copy link
Contributor Author

@ydwu4 ydwu4 Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We move the wrap_to_fake_tensor_and_record logic in wrap_fx_proxy out, so that we could provide an example_value when create_graph_input. Since example_value has already been fakified, it won't get fakified again in wrap_fx_proxy.

@ydwu4 ydwu4 added topic: not user facing topic category and removed release notes: fx release notes category labels Oct 20, 2024
ydwu4 added 2 commits October 21, 2024 13:19
…s take example_value"


Code refactoring only. We move the wrap_to_fake_tensor_logic out of wrap_fx_proxy for placeholders to provide the invariant that **all graph inputs must have example values**


cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec

[ghstack-poisoned]
…s take example_value"


Code refactoring only. We move the wrap_to_fake_tensor_logic out of wrap_fx_proxy for placeholders to provide the invariant that **all graph inputs must have example values**


cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec

[ghstack-poisoned]
class fwd_body_0(torch.nn.Module):
def forward(self, ctx, x: "f32[]", z: "f32[]", l_weird_b: "f32[]", l_weird_c: "f32[]"):
def forward(self, ctx : torch.autograd.function.Function, x: "f32[]", z: "f32[]", l_weird_b: "f32[]", l_weird_c: "f32[]"):
Copy link
Contributor Author

@ydwu4 ydwu4 Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx's type is torch.autograd.funciton.Function instead of FunctionCtx because of https://github.com/pytorch/pytorch/blob/main/torch/_dynamo/side_effects.py#L270

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What causes some of these to state their types but some of them not to?

…s take example_value"


Code refactoring only. We move the wrap_to_fake_tensor_logic out of wrap_fx_proxy for placeholders to provide the invariant that **all graph inputs must set their example values when creating the inputs**. This invariant helps us to identify all the free symbols in the graph in top-level and sub-graphs.


cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec

[ghstack-poisoned]
…s take example_value"


Code refactoring only. We move the wrap_to_fake_tensor_logic out of wrap_fx_proxy for placeholders to provide the invariant that **all graph inputs must set their example values when creating the inputs**. This invariant helps us to identify all the free symbols in the graph in top-level and sub-graphs.


cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec

[ghstack-poisoned]
@ydwu4 ydwu4 added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 25, 2024
…s take example_value"


Code refactoring only. We move the wrap_to_fake_tensor_logic out of wrap_fx_proxy for placeholders to provide the invariant that **all graph inputs must set their example values when creating the inputs**. This invariant helps us to identify all the free symbols in the graph in top-level and sub-graphs.


cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec

[ghstack-poisoned]
gm.cond_fn_0.code.strip(),
"""\
def forward(self, l_iter_, l_x_, l_self_buffers_dec__cond_fn, l_self_modules_linear_parameters_bias__body_fn, l_self_modules_linear_parameters_weight__body_fn):
def forward(self, l_iter_ : torch.Tensor, l_x_ : torch.Tensor, l_self_buffers_dec__cond_fn, l_self_modules_linear_parameters_bias__body_fn, l_self_modules_linear_parameters_weight__body_fn):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do the l_self_buffers_dec__cond_fn don't have types?

if self.backward_state_proxy is None:
if self.export:
unimplemented("backward_state does not support export")
example_value = BackwardState()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check (add a test?) that this doesn't cause a warning? Direct initialization of FunctionCtx usually induces a warniing

proxy = self.root_tracer.create_graph_input(
str(s0),
torch.SymInt,
type(s),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to pass type(s) if there's always an example value? create_graph_input can always get the type from the example value.

Copy link
Contributor

@zou3519 zou3519 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test that creating the backward state does not add user-facing warnings? We've had that problem in the past.

Other than that, this looks fine to me

ydwu4 added 2 commits October 28, 2024 15:48
…s take example_value"


Code refactoring only. We move the wrap_to_fake_tensor_logic out of wrap_fx_proxy for placeholders to provide the invariant that **all graph inputs must set their example values when creating the inputs**. This invariant helps us to identify all the free symbols in the graph in top-level and sub-graphs.


cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec

[ghstack-poisoned]
…s take example_value"


Code refactoring only. We move the wrap_to_fake_tensor_logic out of wrap_fx_proxy for placeholders to provide the invariant that **all graph inputs must set their example values when creating the inputs**. This invariant helps us to identify all the free symbols in the graph in top-level and sub-graphs.


cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec

[ghstack-poisoned]
pytorchmergebot pushed a commit that referenced this pull request Nov 4, 2024
atalman pushed a commit to atalman/pytorch that referenced this pull request Nov 4, 2024
…ing to subgraph (pytorch#138559)

This refactoring is for getting a deterministic ordering of binding tensors and sizes of tensors. When seeing a free tensor  x with shape (s0,) in subgraph, the ordering of lifting changes from
```
lift_x_in_child, lift_s0_in_child, lift_s0_in_parent, lift_x_in_parent
```
to
```
lift_x_in_parent, lift_s0_in_parent, lift_x_in_child, lift_s0_in_child
```
This produces a determinstic ordering of handling the symints in lifted tensors.

This is also the current contract of dynamo top-level graph: we lift free_symbols in sizes after tensor x and insert the free symbols before the tensor x's proxy.

Pull Request resolved: pytorch#138559
Approved by: https://github.com/zou3519
ghstack dependencies: pytorch#138345, pytorch#138428, pytorch#138558, pytorch#138737
pytorchmergebot pushed a commit that referenced this pull request Nov 5, 2024
…p_fx_proxy. (#139663)

Refactoring only. Previously, we manually cal SymNodeVariable.create, now we handle it with wrap_fx_proxy. This unifies the handling of operations that produce symints in wrap_fx_proxy.

Pull Request resolved: #139663
Approved by: https://github.com/zou3519
ghstack dependencies: #138345, #138428, #138558, #138737, #138559
@github-actions github-actions bot deleted the gh/ydwu4/162/head branch December 5, 2024 02:14
pobin6 pushed a commit to pobin6/pytorch that referenced this pull request Dec 5, 2024
…p_fx_proxy. (pytorch#139663)

Refactoring only. Previously, we manually cal SymNodeVariable.create, now we handle it with wrap_fx_proxy. This unifies the handling of operations that produce symints in wrap_fx_proxy.

Pull Request resolved: pytorch#139663
Approved by: https://github.com/zou3519
ghstack dependencies: pytorch#138345, pytorch#138428, pytorch#138558, pytorch#138737, pytorch#138559
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants