Skip to content

Commit

Permalink
fix bugs in export docstrings (pytorch#110169)
Browse files Browse the repository at this point in the history
First error

```
Traceback (most recent call last):
  File "/home/ubuntu/exporty.py", line 8, in <module>
    ep = torch.export.export(MyModule(), torch.randn(5))
  File "/opt/conda/envs/sam/lib/python3.10/site-packages/torch/export/__init__.py", line 509, in export
    return export(f, args, kwargs, constraints)
  File "/opt/conda/envs/sam/lib/python3.10/site-packages/torch/_export/__init__.py", line 314, in export
    raise UserError(UserErrorType.INVALID_INPUT,
torch._dynamo.exc.UserError: Expecting `args` to be a tuple of example positional inputs, got <class 'torch.Tensor'>
```

Second error

```
(sam) ubuntu@ip-172-31-9-217:~$ python exporty.py
Traceback (most recent call last):
  File "/home/ubuntu/exporty.py", line 13, in <module>
    torch.export.save(ep, 'exported_program.pt2', extra_files=extra_files)
  File "/opt/conda/envs/sam/lib/python3.10/site-packages/torch/export/__init__.py", line 566, in save
    save(ep, f, extra_files=extra_files, opset_version=opset_version)
  File "/opt/conda/envs/sam/lib/python3.10/site-packages/torch/_export/__init__.py", line 595, in save
    encoded_content = content.encode('utf-8')
AttributeError: 'bytes' object has no attribute 'encode'. Did you mean: 'decode'?
```
Pull Request resolved: pytorch#110169
Approved by: https://github.com/angelayi
  • Loading branch information
msaroufim authored and pytorchmergebot committed Sep 27, 2023
1 parent bf7307a commit 40b83d9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions torch/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ class MyModule(torch.nn.Module):
def forward(self, x):
return x + 10
ep = torch.export.export(MyModule(), torch.randn(5))
ep = torch.export.export(MyModule(), (torch.randn(5),))
# Save to file
torch.export.save(ep, 'exported_program.pt2')
Expand All @@ -635,7 +635,7 @@ def forward(self, x):
torch.export.save(ep, buffer)
# Save with extra files
extra_files = {'foo.txt': b'bar'}
extra_files = {'foo.txt': b'bar'.decode('utf-8')}
torch.export.save(ep, 'exported_program.pt2', extra_files=extra_files)
"""
Expand Down Expand Up @@ -693,7 +693,7 @@ def load(
extra_files = {'foo.txt': ''} # values will be replaced with data
ep = torch.export.load('exported_program.pt2', extra_files=extra_files)
print(extra_files['foo.txt'])
print(ep(torch.randn(5)))
"""
from torch._export import load

Expand Down

0 comments on commit 40b83d9

Please sign in to comment.