Skip to content

Commit

Permalink
torchbench is now a library (#1933)
Browse files Browse the repository at this point in the history
Summary:
```python
import torchbenchmark.models.densenet121
model, example_inputs = torchbenchmark.models.densenet121.Model(test="eval", device="cuda", batch_size=1).get_module()
model(*example_inputs)
```

So making the above example work with `import torchbenchmark` alone is a bit trickier there's a lot of relative imports that need to be fixed in pretty much every single file

I also added a simple `test_imports.py` file to make sure this doesn't break anything, I can setup a standalone github action or plug into an existing one (would rather do the latter to avoid another job that needs to run `install.py` again

This also solves voznesenskym favorite design pattern from https://github.com/pytorch/pytorch/blob/main/benchmarks/dynamo/torchbench.py

```python
    for torchbench_dir in (
        "./torchbenchmark",
        "../torchbenchmark",
        "../torchbench",
        "../benchmark",
        "../../torchbenchmark",
        "../../torchbench",
        "../../benchmark",
    ):
```

Pull Request resolved: #1933

Reviewed By: xuzhao9

Differential Revision: D49608012

Pulled By: msaroufim

fbshipit-source-id: 382a31f2c5a464608faa730ae15148f59a3e7484
  • Loading branch information
msaroufim authored and facebook-github-bot committed Sep 25, 2023
1 parent 75889b4 commit f2d615b
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ old.json
te.json
logs/
scripts/scribe.py
.userbenchmark/
.userbenchmark/
torchbench.egg-info/
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@ cd benchmark
python install.py
```

### Install torchbench as a library

if you're interested in running torchbench as a library you can

```bash
python install.py
pip install git+https://www.github.com:pytorch/benchmark.git
```

or

```bash
python install.py
pip install . # add -e for an editable installation
```

The above

```python
import torchbenchmark.models.densenet121
model, example_inputs = torchbenchmark.models.densenet121.Model(test="eval", device="cuda", batch_size=1).get_module()
model(*example_inputs)
```

### Building From Source
Note that when building PyTorch from source, torchvision and torchaudio must also be built from source to make sure the C APIs match.

Expand Down
16 changes: 16 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from setuptools import setup, find_packages

setup(
name='torchbench',
version='0.1',
description='Benchmarking library for PyTorch',
author='PyTorch Team',
url='https://github.com/pytorch/benchmark',
packages=find_packages(include=['torchbenchmark*', 'userbenchmark*']),
classifiers=[
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: BSD 3 License',
'Programming Language :: Python',
],
)
8 changes: 8 additions & 0 deletions test_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import torchbenchmark.models.densenet121
model, example_inputs = torchbenchmark.models.densenet121.Model(test="eval", device="cuda", batch_size=1).get_module()
model(*example_inputs)

import userbenchmark.optim
import torchbenchmark.canary_models
import torchbenchmark.models
import torchbenchmark.score
4 changes: 4 additions & 0 deletions torchbenchmark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

from components._impl.tasks import base as base_task
from components._impl.workers import subprocess_worker
from . import models
from . import canary_models
from . import e2e_models
from . import util

class ModelNotFoundError(RuntimeError):
pass
Expand Down
1 change: 1 addition & 0 deletions torchbenchmark/canary_models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions torchbenchmark/e2e_models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions torchbenchmark/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions torchbenchmark/score/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit f2d615b

Please sign in to comment.