Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a4dfaa6
Move C/C++ files to core
jansel Oct 7, 2022
260066e
Fixing issues
jansel Oct 7, 2022
1646d9d
lints
jansel Oct 7, 2022
04ac91f
Merge branch 'main' of github.com:pytorch/torchdynamo into core
jansel Oct 7, 2022
f59feb0
bits
jansel Oct 7, 2022
67f50fd
Lints in core
jansel Oct 7, 2022
11b1170
Merge branch 'main' of github.com:pytorch/torchdynamo into core
jansel Oct 7, 2022
40a2fd6
Merge branch 'main' of github.com:pytorch/torchdynamo into core
jansel Oct 8, 2022
ba35c19
fix
jansel Oct 8, 2022
2993bd3
enable tests
jansel Oct 8, 2022
0726443
Merge branch 'main' of github.com:pytorch/torchdynamo into core
jansel Oct 8, 2022
ad061f5
.
jansel Oct 8, 2022
57015a3
fix
jansel Oct 8, 2022
25d768e
.
jansel Oct 9, 2022
ad858bd
Merge branch 'main' of github.com:pytorch/torchdynamo into core
jansel Oct 9, 2022
30cef25
.
jansel Oct 9, 2022
6818206
.
jansel Oct 9, 2022
440e1c3
Merge branch 'main' of github.com:pytorch/torchdynamo into core
jansel Oct 9, 2022
d18aff3
asan
jansel Oct 10, 2022
ddcd263
Merge branch 'main' of github.com:pytorch/torchdynamo into core
jansel Oct 10, 2022
7954dc1
Merge branch 'main' of github.com:pytorch/torchdynamo into core
jansel Oct 10, 2022
7f7c4b0
.
jansel Oct 10, 2022
151fc25
.
jansel Oct 11, 2022
e6f3ffb
Filelock fix
jansel Oct 11, 2022
09039dd
filelock_skip
jansel Oct 11, 2022
ef15752
.
jansel Oct 11, 2022
75f2c9e
.
jansel Oct 12, 2022
8866ec9
Update PyTorch pin
desertfire Oct 12, 2022
088f561
Circular import
jansel Oct 12, 2022
52b4c8e
Merge branch 'binbao/update_pytorch_pin' of github.com:pytorch/torchd…
jansel Oct 12, 2022
4a59e6e
Unbound local
jansel Oct 12, 2022
4080e1b
fsdp import error
jansel Oct 12, 2022
0641c87
jinja
jansel Oct 12, 2022
f958df8
Merge branch 'main' of github.com:pytorch/torchdynamo into core
jansel Oct 12, 2022
a7d0756
.
jansel Oct 12, 2022
3409d31
.
jansel Oct 12, 2022
bc0ebf5
.
jansel Oct 13, 2022
9205e10
.
jansel Oct 13, 2022
c8859c0
Merge branch 'main' of github.com:pytorch/torchdynamo into core
jansel Oct 13, 2022
c5064f4
Merge branch 'main' of github.com:pytorch/torchdynamo into core
jansel Oct 13, 2022
dafd15d
Merge branch 'main' of github.com:pytorch/torchdynamo into core
jansel Oct 13, 2022
dcc079a
Enable tests
jansel Oct 14, 2022
a384a76
.
jansel Oct 14, 2022
0845624
.
jansel Oct 14, 2022
614514e
Workaround
jansel Oct 14, 2022
841b3bf
Move testcase to workaround import side effects
jansel Oct 14, 2022
739c299
.
jansel Oct 14, 2022
a990f3f
Merge branch 'main' of github.com:pytorch/torchdynamo into core
jansel Oct 14, 2022
96fd6b1
.
jansel Oct 14, 2022
38ef976
Fix base_dir
jansel Oct 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,11 @@ overhead: develop
format:
isort $(PY_FILES)
black $(PY_FILES)
! which $(CLANG_FORMAT) >/dev/null 2>&1 || $(CLANG_FORMAT) -i $(C_FILES)

lint:
black --check --diff $(PY_FILES)
isort --check --diff $(PY_FILES)
flake8 $(PY_FILES)
mypy
! which $(CLANG_TIDY) >/dev/null 2>&1 || $(CLANG_TIDY) $(C_FILES) -- \
-I`python -c 'from distutils.sysconfig import get_python_inc as X; print(X())'` \
`python -c 'from torch.utils.cpp_extension import include_paths; print(" ".join(map("-I{}".format, include_paths())))'`

lint-deps:
grep -E '(black|flake8|isort|click|torch|mypy)' requirements.txt | xargs $(PIP) install
Expand Down
55 changes: 28 additions & 27 deletions benchmarks/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import argparse
import collections
import copy
Expand Down Expand Up @@ -891,6 +891,33 @@ def scale(self, loss):
return loss


def maybe_fresh_cache(fn):
def inner(self, *args, **kwargs):
cache_minder = NullContext()
if self.args.cold_start_latency:
cache_entries = {}
cache_minder = fresh_triton_cache(cache_entries)

try:
with cache_minder:
return fn(self, *args, **kwargs)
finally:
dump_cache = False
if dump_cache and self.args.cold_start_latency:
output_csv(
output_filename[:-4] + "_triton_cache.csv",
["dev", "name", "batch_size", "triton_cache"],
[
current_device,
current_name,
current_batch_size,
cache_entries,
],
)

return inner


class BenchmarkRunner:
def __init__(self):
self.model_iter_fn = None
Expand Down Expand Up @@ -1285,32 +1312,6 @@ def compare_branches(
"--diff_main called on main branch, what are you diffing?"
)

def maybe_fresh_cache(fn):
def inner(self, *args, **kwargs):
cache_minder = NullContext()
if self.args.cold_start_latency:
cache_entries = {}
cache_minder = fresh_triton_cache(cache_entries)

try:
with cache_minder:
return fn(self, *args, **kwargs)
finally:
dump_cache = False
if dump_cache and self.args.cold_start_latency:
output_csv(
output_filename[:-4] + "_triton_cache.csv",
["dev", "name", "batch_size", "triton_cache"],
[
current_device,
current_name,
current_batch_size,
cache_entries,
],
)

return inner

@maybe_fresh_cache
def run_one_model(
self,
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/huggingface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import importlib
import logging
import os
Expand Down
1 change: 1 addition & 0 deletions benchmarks/microbenchmarks/bench_conv_fusion.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa
import model
import torch
import triton
Expand Down
1 change: 1 addition & 0 deletions benchmarks/microbenchmarks/bench_mm_fusion.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa
import torch
import triton
from prettytable import PrettyTable
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/microbenchmarks/benchmark_helper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from torch.utils.benchmark import Timer


def time_with_torch_timer(fn, args, kwargs={}, iters=100):
def time_with_torch_timer(fn, args, kwargs=None, iters=100):
kwargs = kwargs or {}
env = {"args": args, "kwargs": kwargs, "fn": fn}
fn_call = "fn(*args, **kwargs)"

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/microbenchmarks/microbench.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import argparse
import inspect
import sys
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/microbenchmarks/operator_inp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def serialize_sparse_tensor(e):


def deserialize_sparse_tensor(size, dtype, layout, is_coalesced, nnz=None):
assert False, "NYI"
raise NotImplementedError()


def deserialize_tensor(size, dtype, stride=None):
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/microbenchmarks/operatorbench.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import click
import numpy as np
import torch
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/runner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

"""
A wrapper over the benchmark infrastructure to generate commonly used commands,
Expand Down
7 changes: 3 additions & 4 deletions benchmarks/timm_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import importlib
import logging
import os
Expand Down Expand Up @@ -30,9 +30,8 @@ def pip_install(package):
from timm.models import create_model

TIMM_MODELS = dict()
filename = "timm_models_list.txt"
if os.path.exists("benchmarks"):
filename = "benchmarks/" + filename
filename = os.path.join(os.path.dirname(__file__), "timm_models_list.txt")

with open(filename, "r") as fh:
lines = fh.readlines()
lines = [line.rstrip() for line in lines]
Expand Down
4 changes: 3 additions & 1 deletion benchmarks/torchbench.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import gc
import importlib
import logging
Expand Down Expand Up @@ -240,6 +240,8 @@ def load_model(
if batch_size is None and is_training and model_name in USE_SMALL_BATCH_SIZE:
batch_size = USE_SMALL_BATCH_SIZE[model_name]

# workaround "RuntimeError: not allowed to set torch.backends.cudnn flags"
torch.backends.__allow_nonbracketed_mutation_flag = True
if is_training:
benchmark = benchmark_cls(
test="train", device=device, jit=False, batch_size=batch_size
Expand Down
Empty file modified benchmarks/training_loss.py
100755 → 100644
Empty file.
17 changes: 17 additions & 0 deletions copy_to_core.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -ex

rsync -ra ~/torchdynamo/torchdynamo/ ~/pytorch/torch/_dynamo
rsync -ra ~/torchdynamo/torchinductor/ ~/pytorch/torch/_inductor
rsync -ra ~/torchdynamo/test/{dynamo,inductor} ~/pytorch/test/
rsync -ra ~/torchdynamo/benchmarks/ ~/pytorch/benchmarks/dynamo

for DIR in ~/pytorch/test/{dynamo,inductor} ~/pytorch/benchmarks/dynamo
do
find $DIR -name '*.py' | xargs -n1 -- sed -i 's/torchdynamo/torch._dynamo/g'
find $DIR -name '*.py' | xargs -n1 -- sed -i 's/torchinductor/torch._inductor/g'
find $DIR -name '*.py' | xargs -n1 -- sed -i 's/_torch[.]_inductor/_torchinductor/g'
find $DIR -name '*.py' | xargs -n1 -- sed -i 's@pytorch/torch[.]_dynamo@pytorch/torchdynamo@g'
done

(cd ~/pytorch && (lintrunner -a || lintrunner -a))
20 changes: 3 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env python
import sys

from setuptools import Extension
from setuptools import find_packages
from setuptools import setup
from torch.utils.cpp_extension import CppExtension

long_description = """
TorchDynamo is a Python-level JIT compiler designed to make unmodified
Expand All @@ -31,7 +29,7 @@
]

install_requires = [
"torch>=1.12.0",
"torch>=1.13.0",
"numpy",
"tabulate",
"pyyaml",
Expand All @@ -43,13 +41,13 @@

setup(
name="torchdynamo",
version="1.13.0.dev0",
version="1.14.0.dev0",
url="https://github.com/pytorch/torchdynamo",
description="A Python-level JIT compiler designed to make unmodified PyTorch programs faster.",
long_description=long_description,
long_description_content_type="text/markdown",
author="Jason Ansel",
author_email="jansel@fb.com",
author_email="jansel@meta.com",
license="BSD-3",
keywords="pytorch machine learning compilers",
python_requires=">=3.7, <3.11",
Expand All @@ -59,16 +57,4 @@
"torchinductor.codegen": ["*.h", "*.j2"],
},
zip_safe=False,
ext_modules=[
Extension(
"torchdynamo._eval_frame",
["torchdynamo/_eval_frame.c"],
extra_compile_args=["-Wall"],
),
CppExtension(
name="torchdynamo._guards",
sources=["torchdynamo/_guards.cpp"],
extra_compile_args=["-std=c++14"],
),
],
)
2 changes: 1 addition & 1 deletion test/dynamo/mock_modules/mock_module2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ def method2(self, x):


def method1(x, y):
z = torch.ones(1, 1) # noqa
torch.ones(1, 1)
x.append(y)
return x
2 changes: 1 addition & 1 deletion test/dynamo/mock_modules/mock_module3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


def method1(x, y):
z = torch.ones(1, 1) # noqa
torch.ones(1, 1)
x.append(y)
return x
15 changes: 11 additions & 4 deletions test/dynamo/test_aot_autograd.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env pytest
# Owner(s): ["module: dynamo"]
import functools

import torch

import torchdynamo
import torchdynamo.test_case
from torchdynamo.optimizations.training import is_aot_autograd_safe_to_run
from torchdynamo.testing import rand_strided

Expand All @@ -13,14 +14,14 @@ def compiler_safe_fn(gm, example_inputs, is_safe):
return gm.forward


class AotAutogradFallbackTests(torchdynamo.testing.TestCase):
class AotAutogradFallbackTests(torchdynamo.test_case.TestCase):
def test_LSTM(self):
# https://github.com/pytorch/torchdynamo/issues/1147
class Repro(torch.nn.Module):
def __init__(self):
super().__init__()
self.self_mod_model_lstm_lstm = torch.nn.LSTM(
2048, 2048, num_layers=2, bidirectional=True
64, 64, num_layers=2, bidirectional=True
)

def forward(self, permute: torch.Tensor):
Expand All @@ -32,7 +33,7 @@ def forward(self, permute: torch.Tensor):
compiler_fn = functools.partial(compiler_safe_fn, is_safe=is_safe)
aot_mod = torchdynamo.optimize(compiler_fn)(mod)

args = [((92, 4, 2048), (1, 188416, 92), torch.float32, "cpu", False)]
args = [((92, 4, 64), (1, 5888, 92), torch.float32, "cpu", False)]
args = [
rand_strided(sh, st, dt, dev).requires_grad_(rg)
for (sh, st, dt, dev, rg) in args
Expand Down Expand Up @@ -130,3 +131,9 @@ def fn(x, y):
aot_fn = torchdynamo.optimize(compiler_fn)(fn)
aot_fn(x, y)
self.assertTrue(is_safe[0])


if __name__ == "__main__":
from torchdynamo.test_case import run_tests

run_tests()
8 changes: 5 additions & 3 deletions test/dynamo/test_aot_cudagraphs.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env pytest
# Owner(s): ["module: cuda graphs"]

import functools
Expand All @@ -8,6 +7,7 @@
import torch

import torchdynamo
import torchdynamo.test_case
import torchdynamo.testing
from torchdynamo.testing import same

Expand Down Expand Up @@ -53,7 +53,7 @@ def patch_all(ok=True):


@unittest.skipIf(not torch.cuda.is_available(), "these tests require cuda")
class TestAotCudagraphs(torchdynamo.testing.TestCase):
class TestAotCudagraphs(torchdynamo.test_case.TestCase):
@patch_all()
def test_basic(self):
def model(x, y):
Expand Down Expand Up @@ -202,4 +202,6 @@ def fn(x):


if __name__ == "__main__":
unittest.main()
from torchdynamo.test_case import run_tests

run_tests()
Loading