Skip to content

Conversation

@yushangdi
Copy link
Contributor

@yushangdi yushangdi commented Nov 20, 2024

Summary:
repro.py can have nested graph modules, e.g.

class Repro(torch.nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.true_graph_0 = GraphModule()



    def forward(self):
        true_graph_0 = self.true_graph_0
        return (true_graph_0,)

So dumping the string doesn’t always work.

So,

  1. we use exported program in repro.py instead
  2. we still dump the graph module string, but only put it in comments

We also added two flags to minifier_launcher.py

  • minifier-export-mode: whether strict or non-strict export is used in the minifier
  • skip-export-error: intermediate graphs that cannot be exported will be skipped.

Test Plan:

buck2 run  fbcode//caffe2/test/inductor:minifier_utils_cpu  -- -r string
python test/inductor/test_minifier.py

Differential Revision: D66175257

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @ColinPeppler @amjames @desertfire @chauhang @aakhundov

@pytorch-bot
Copy link

pytorch-bot bot commented Nov 20, 2024

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit f148683 with merge base 149677e (image):
💚 Looks good so far! There are no failures yet. 💚

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

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66175257

@henrylhtsang
Copy link
Contributor

buck2 run fbcode//caffe2/test/inductor:minifier_utils_cpu -- -r string

nit: generally its a good idea to keep fbcode and oss separated. But I find it hard as well

elif gm is None:
gm = exported_program.module()

# save a graph preview using gm
Copy link
Contributor

Choose a reason for hiding this comment

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

so just to be clear, gm is just for string. exported_program is the thing that actually matters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so just to be clear, gm is just for string. exported_program is the thing that actually matters?

Yes, but note that we also have exported_program = torch.export.export(gm, args, strict=strict) three lines above. So if the input is gm, the exported_program is generated from gm, so in some sense, gm also matters.

save_dir=subdir,
command="minify",
options=options,
config_patches=options,
Copy link
Contributor

Choose a reason for hiding this comment

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

so it will just use strict = 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.

so it will just use strict = False?

By default yes, but you can set minifier_export_mode="dynamo" kwarg in the run_repro() function in minifier_launcher to change it to use strict=True.

I'll update the doc to include this later (the doc is a bit annoying to edit because the doc build can fail if not edited carefully, so I prefer to update the doc in a separate PR).

command="run",
accuracy=None,
check_str=None,
module_in_comment=False,
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you will use it in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess you will use it in the future?

yes! I think this PR is getting a little long already.

Basically, it's for not having the module in comment in minifier_launcher.py, since the module can be quite large.

return None
raise AOTIMinifierError(e) from e

return None
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure what this does but okay

Copy link
Contributor Author

@yushangdi yushangdi Nov 21, 2024

Choose a reason for hiding this comment

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

not sure what this does but okay

yeah we should never reach here. I'll add a comment.

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 21, 2024
facebook-github-bot pushed a commit that referenced this pull request Nov 21, 2024
Summary:

`repro.py` can have nested graph modules, e.g.

```
class Repro(torch.nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.true_graph_0 = GraphModule()



    def forward(self):
        true_graph_0 = self.true_graph_0
        return (true_graph_0,)
```

So dumping the string doesn’t always work.

So,
1) we use exported program in repro.py instead
2) we still dump the graph module string, but only put it in comments


We also added two flags to `minifier_launcher.py`
- `minifier-export-mode`: whether strict or non-strict export is used in the minifier
- `skip-export-error`: intermediate graphs that cannot be exported will be skipped.

Test Plan:
```
buck2 run  fbcode//caffe2/test/inductor:minifier_utils_cpu  -- -r string
python test/inductor/test_minifier.py
```

Reviewed By: henrylhtsang

Differential Revision: D66175257
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66175257

facebook-github-bot pushed a commit that referenced this pull request Nov 21, 2024
Summary:

`repro.py` can have nested graph modules, e.g.

```
class Repro(torch.nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.true_graph_0 = GraphModule()



    def forward(self):
        true_graph_0 = self.true_graph_0
        return (true_graph_0,)
```

So dumping the string doesn’t always work.

So,
1) we use exported program in repro.py instead
2) we still dump the graph module string, but only put it in comments


We also added two flags to `minifier_launcher.py`
- `minifier-export-mode`: whether strict or non-strict export is used in the minifier
- `skip-export-error`: intermediate graphs that cannot be exported will be skipped.

Test Plan:
```
buck2 run  fbcode//caffe2/test/inductor:minifier_utils_cpu  -- -r string
python test/inductor/test_minifier.py
```

Reviewed By: henrylhtsang

Differential Revision: D66175257
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66175257

Summary:

`repro.py` can have nested graph modules, e.g.

```
class Repro(torch.nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.true_graph_0 = GraphModule()



    def forward(self):
        true_graph_0 = self.true_graph_0
        return (true_graph_0,)
```

So dumping the string doesn’t always work.

So,
1) we use exported program in repro.py instead
2) we still dump the graph module string, but only put it in comments


We also added two flags to `minifier_launcher.py`
- `minifier-export-mode`: whether strict or non-strict export is used in the minifier
- `skip-export-error`: intermediate graphs that cannot be exported will be skipped.

Test Plan:
```
buck2 run  fbcode//caffe2/test/inductor:minifier_utils_cpu  -- -r string
python test/inductor/test_minifier.py
```

Reviewed By: henrylhtsang

Differential Revision: D66175257
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66175257

@facebook-github-bot
Copy link
Contributor

@pytorchbot merge

(Initiating merge automatically since Phabricator Diff has merged)

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

pobin6 pushed a commit to pobin6/pytorch that referenced this pull request Dec 5, 2024
Summary:
`repro.py` can have nested graph modules, e.g.

```
class Repro(torch.nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.true_graph_0 = GraphModule()

    def forward(self):
        true_graph_0 = self.true_graph_0
        return (true_graph_0,)
```

So dumping the string doesn’t always work.

So,
1) we use exported program in repro.py instead
2) we still dump the graph module string, but only put it in comments

We also added two flags to `minifier_launcher.py`
- `minifier-export-mode`: whether strict or non-strict export is used in the minifier
- `skip-export-error`: intermediate graphs that cannot be exported will be skipped.

Test Plan:
```
buck2 run  fbcode//caffe2/test/inductor:minifier_utils_cpu  -- -r string
python test/inductor/test_minifier.py
```

Differential Revision: D66175257

Pull Request resolved: pytorch#141159
Approved by: https://github.com/henrylhtsang
@github-actions github-actions bot deleted the export-D66175257 branch December 22, 2024 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants