Skip to content

Commit 2e6a4d5

Browse files
committed
Update base for Update on "[WIP] Compute forward grads for saved_mean and saved_var when input requires grad"
We want to avoid having to recompute saved_mean and saved_invstd in batch_norm_backward's decomposition in functorch (see pytorch/functorch#877), but also avoid unnecessarily computing forward grads for saved_mean and saved_invstd when they are not needed. Tested locally with: `python test/test_ops.py -k test_jvpvjp_nn_functional_batch_norm` Issues: - not sure if gradgrad in core is missing something, but it is able to pass while the fwgrad_bwgrad comparison fails in functorch [ghstack-poisoned]
2 parents 0c63027 + 4a5fdc5 commit 2e6a4d5

File tree

2,902 files changed

+210068
-142501
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,902 files changed

+210068
-142501
lines changed

.circleci/cimodel/data/dimensions.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"102",
55
"113",
66
"116",
7+
"117",
78
]
89

910
ROCM_VERSIONS = [

.circleci/cimodel/data/simple/ios_definitions.py

+21-27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from cimodel.data.simple.util.versions import MultiPartVersion
2+
from cimodel.data.simple.util.branch_filters import gen_filter_dict_exclude
23
import cimodel.lib.miniutils as miniutils
34

45
XCODE_VERSION = MultiPartVersion([12, 5, 1])
@@ -11,7 +12,7 @@ def __init__(self, name, custom_build_name=""):
1112

1213
def render(self):
1314
extra_parts = [self.custom_build_name] if len(self.custom_build_name) > 0 else []
14-
return "_".join([self.name] + extra_parts)
15+
return "-".join([self.name] + extra_parts).replace("_", "-")
1516

1617

1718
def get_platform(arch_variant_name):
@@ -25,30 +26,25 @@ def __init__(self, xcode_version, arch_variant, is_org_member_context=True, extr
2526
self.is_org_member_context = is_org_member_context
2627
self.extra_props = extra_props
2728

28-
def gen_name_parts(self, with_version_dots):
29-
30-
version_parts = self.xcode_version.render_dots_or_parts(with_version_dots)
31-
build_variant_suffix = "_".join([self.arch_variant.render(), "build"])
32-
29+
def gen_name_parts(self):
30+
version_parts = self.xcode_version.render_dots_or_parts("-")
31+
build_variant_suffix = self.arch_variant.render()
3332
return [
34-
"pytorch",
3533
"ios",
3634
] + version_parts + [
3735
build_variant_suffix,
3836
]
3937

4038
def gen_job_name(self):
41-
return "_".join(self.gen_name_parts(False))
39+
return "-".join(self.gen_name_parts())
4240

4341
def gen_tree(self):
44-
4542
platform_name = get_platform(self.arch_variant.name)
46-
4743
props_dict = {
48-
"build_environment": "-".join(self.gen_name_parts(True)),
44+
"name": self.gen_job_name(),
45+
"build_environment": self.gen_job_name(),
4946
"ios_arch": self.arch_variant.name,
5047
"ios_platform": platform_name,
51-
"name": self.gen_job_name(),
5248
}
5349

5450
if self.is_org_member_context:
@@ -57,30 +53,28 @@ def gen_tree(self):
5753
if self.extra_props:
5854
props_dict.update(self.extra_props)
5955

56+
props_dict["filters"] = gen_filter_dict_exclude()
57+
6058
return [{"pytorch_ios_build": props_dict}]
6159

6260

6361
WORKFLOW_DATA = [
6462
IOSJob(XCODE_VERSION, ArchVariant("x86_64"), is_org_member_context=False, extra_props={
6563
"lite_interpreter": miniutils.quote(str(int(True)))}),
66-
IOSJob(XCODE_VERSION, ArchVariant("x86_64", "full_jit"), is_org_member_context=False, extra_props={
67-
"lite_interpreter": miniutils.quote(str(int(False)))}),
68-
IOSJob(XCODE_VERSION, ArchVariant("arm64"), extra_props={
69-
"lite_interpreter": miniutils.quote(str(int(True)))}),
70-
IOSJob(XCODE_VERSION, ArchVariant("arm64", "metal"), extra_props={
71-
"use_metal": miniutils.quote(str(int(True))),
72-
"lite_interpreter": miniutils.quote(str(int(True)))}),
73-
IOSJob(XCODE_VERSION, ArchVariant("arm64", "full_jit"), extra_props={
74-
"lite_interpreter": miniutils.quote(str(int(False)))}),
75-
IOSJob(XCODE_VERSION, ArchVariant("arm64", "custom"), extra_props={
76-
"op_list": "mobilenetv2.yaml",
77-
"lite_interpreter": miniutils.quote(str(int(True)))}),
64+
# IOSJob(XCODE_VERSION, ArchVariant("arm64"), extra_props={
65+
# "lite_interpreter": miniutils.quote(str(int(True)))}),
66+
# IOSJob(XCODE_VERSION, ArchVariant("arm64", "metal"), extra_props={
67+
# "use_metal": miniutils.quote(str(int(True))),
68+
# "lite_interpreter": miniutils.quote(str(int(True)))}),
69+
# IOSJob(XCODE_VERSION, ArchVariant("arm64", "custom-ops"), extra_props={
70+
# "op_list": "mobilenetv2.yaml",
71+
# "lite_interpreter": miniutils.quote(str(int(True)))}),
7872
IOSJob(XCODE_VERSION, ArchVariant("x86_64", "coreml"), is_org_member_context=False, extra_props={
7973
"use_coreml": miniutils.quote(str(int(True))),
8074
"lite_interpreter": miniutils.quote(str(int(True)))}),
81-
IOSJob(XCODE_VERSION, ArchVariant("arm64", "coreml"), extra_props={
82-
"use_coreml": miniutils.quote(str(int(True))),
83-
"lite_interpreter": miniutils.quote(str(int(True)))}),
75+
# IOSJob(XCODE_VERSION, ArchVariant("arm64", "coreml"), extra_props={
76+
# "use_coreml": miniutils.quote(str(int(True))),
77+
# "lite_interpreter": miniutils.quote(str(int(True)))}),
8478
]
8579

8680

.circleci/cimodel/data/simple/macos_definitions.py

+104-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
from collections import OrderedDict
2+
from cimodel.lib.miniutils import quote
3+
from cimodel.data.simple.util.branch_filters import gen_filter_dict_exclude
4+
5+
16
class MacOsJob:
27
def __init__(self, os_version, is_build=False, is_test=False, extra_props=tuple()):
38
# extra_props is tuple type, because mutable data structures for argument defaults
@@ -11,10 +16,14 @@ def gen_tree(self):
1116
non_phase_parts = ["pytorch", "macos", self.os_version, "py3"]
1217

1318
extra_name_list = [name for name, exist in self.extra_props.items() if exist]
14-
full_job_name_list = non_phase_parts + extra_name_list + [
15-
'build' if self.is_build else None,
16-
'test' if self.is_test else None,
17-
]
19+
full_job_name_list = (
20+
non_phase_parts
21+
+ extra_name_list
22+
+ [
23+
"build" if self.is_build else None,
24+
"test" if self.is_test else None,
25+
]
26+
)
1827

1928
full_job_name = "_".join(list(filter(None, full_job_name_list)))
2029

@@ -41,12 +50,99 @@ def gen_tree(self):
4150
"10_13",
4251
is_build=True,
4352
is_test=True,
44-
extra_props=tuple({
45-
"lite_interpreter": True
46-
}.items()),
47-
)
53+
extra_props=tuple({"lite_interpreter": True}.items()),
54+
),
4855
]
4956

5057

58+
def get_new_workflow_jobs():
59+
return [
60+
OrderedDict(
61+
{
62+
"mac_build": OrderedDict(
63+
{
64+
"name": "macos-12-py3-x86-64-build",
65+
"build-environment": "macos-12-py3-x86-64",
66+
"xcode-version": quote("13.3.1"),
67+
"filters": gen_filter_dict_exclude()
68+
}
69+
)
70+
}
71+
),
72+
OrderedDict(
73+
{
74+
"mac_test": OrderedDict(
75+
{
76+
"name": "macos-12-py3-x86-64-test-1-2-default",
77+
"build-environment": "macos-12-py3-x86-64",
78+
"xcode-version": quote("13.3.1"),
79+
"shard-number": quote("1"),
80+
"num-test-shards": quote("2"),
81+
"requires": ["macos-12-py3-x86-64-build"],
82+
"filters": gen_filter_dict_exclude()
83+
}
84+
)
85+
}
86+
),
87+
OrderedDict(
88+
{
89+
"mac_test": OrderedDict(
90+
{
91+
"name": "macos-12-py3-x86-64-test-2-2-default",
92+
"build-environment": "macos-12-py3-x86-64",
93+
"xcode-version": quote("13.3.1"),
94+
"shard-number": quote("2"),
95+
"num-test-shards": quote("2"),
96+
"requires": ["macos-12-py3-x86-64-build"],
97+
"filters": gen_filter_dict_exclude()
98+
}
99+
)
100+
}
101+
),
102+
OrderedDict(
103+
{
104+
"mac_test": OrderedDict(
105+
{
106+
"name": "macos-12-py3-x86-64-test-1-1-functorch",
107+
"build-environment": "macos-12-py3-x86-64",
108+
"xcode-version": quote("13.3.1"),
109+
"shard-number": quote("1"),
110+
"num-test-shards": quote("1"),
111+
"test-config": "functorch",
112+
"requires": ["macos-12-py3-x86-64-build"],
113+
"filters": gen_filter_dict_exclude()
114+
}
115+
)
116+
}
117+
),
118+
OrderedDict(
119+
{
120+
"mac_build": OrderedDict(
121+
{
122+
"name": "macos-12-py3-x86-64-lite-interpreter-build-test",
123+
"build-environment": "macos-12-py3-lite-interpreter-x86-64",
124+
"xcode-version": quote("13.3.1"),
125+
"build-generates-artifacts": "false",
126+
"filters": gen_filter_dict_exclude()
127+
}
128+
)
129+
}
130+
),
131+
OrderedDict(
132+
{
133+
"mac_build": OrderedDict(
134+
{
135+
"name": "macos-12-py3-arm64-build",
136+
"build-environment": "macos-12-py3-arm64",
137+
"xcode-version": quote("13.3.1"),
138+
"python-version": quote("3.9.12"),
139+
"filters": gen_filter_dict_exclude()
140+
}
141+
)
142+
}
143+
),
144+
]
145+
146+
51147
def get_workflow_jobs():
52148
return [item.gen_tree() for item in WORKFLOW_DATA]

.circleci/cimodel/data/simple/nightly_ios.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(self,
1515
def get_phase_name(self):
1616
return "upload" if self.is_upload else "build"
1717

18-
def get_common_name_pieces(self, with_version_dots):
18+
def get_common_name_pieces(self, sep):
1919

2020
extra_name_suffix = [self.get_phase_name()] if self.is_upload else []
2121

@@ -24,7 +24,7 @@ def get_common_name_pieces(self, with_version_dots):
2424
common_name_pieces = [
2525
"ios",
2626
] + extra_name + [
27-
] + ios_definitions.XCODE_VERSION.render_dots_or_parts(with_version_dots) + [
27+
] + ios_definitions.XCODE_VERSION.render_dots_or_parts(sep) + [
2828
"nightly",
2929
self.variant,
3030
"build",
@@ -33,14 +33,14 @@ def get_common_name_pieces(self, with_version_dots):
3333
return common_name_pieces
3434

3535
def gen_job_name(self):
36-
return "_".join(["pytorch"] + self.get_common_name_pieces(False))
36+
return "_".join(["pytorch"] + self.get_common_name_pieces(None))
3737

3838
def gen_tree(self):
3939
build_configs = BUILD_CONFIGS_FULL_JIT if self.is_full_jit else BUILD_CONFIGS
4040
extra_requires = [x.gen_job_name() for x in build_configs] if self.is_upload else []
4141

4242
props_dict = {
43-
"build_environment": "-".join(["libtorch"] + self.get_common_name_pieces(True)),
43+
"build_environment": "-".join(["libtorch"] + self.get_common_name_pieces(".")),
4444
"requires": extra_requires,
4545
"context": "org-member",
4646
"filters": {"branches": {"only": "nightly"}},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from typing import OrderedDict
2+
from cimodel.data.simple.util.branch_filters import gen_filter_dict_exclude
3+
4+
5+
def get_workflow_job():
6+
return [
7+
OrderedDict(
8+
{
9+
"upload_test_stats": OrderedDict(
10+
{
11+
"name": "upload test status",
12+
"requires": [
13+
"macos-12-py3-x86-64-test-1-2-default",
14+
"macos-12-py3-x86-64-test-2-2-default",
15+
"macos-12-py3-x86-64-test-1-1-functorch",
16+
],
17+
"filters": gen_filter_dict_exclude()
18+
}
19+
)
20+
}
21+
),
22+
]

.circleci/cimodel/data/simple/util/branch_filters.py

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
RC_PATTERN = r"/v[0-9]+(\.[0-9]+)*-rc[0-9]+/"
1414

15+
MAC_IOS_EXCLUSION_LIST = ["nightly", "postnightly"]
16+
17+
1518
def gen_filter_dict(
1619
branches_list=NON_PR_BRANCH_LIST,
1720
tags_list=None
@@ -26,3 +29,11 @@ def gen_filter_dict(
2629
if tags_list is not None:
2730
filter_dict["tags"] = {"only": tags_list}
2831
return filter_dict
32+
33+
34+
def gen_filter_dict_exclude(branches_list=MAC_IOS_EXCLUSION_LIST):
35+
return {
36+
"branches": {
37+
"ignore": branches_list,
38+
},
39+
}

.circleci/cimodel/data/simple/util/versions.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from typing import Optional
2+
3+
14
class MultiPartVersion:
25
def __init__(self, parts, prefix=""):
36
self.parts = parts
@@ -13,14 +16,11 @@ def prefixed_parts(self):
1316
else:
1417
return [self.prefix]
1518

16-
def render_dots(self):
17-
return ".".join(self.prefixed_parts())
18-
19-
def render_dots_or_parts(self, with_dots):
20-
if with_dots:
21-
return [self.render_dots()]
22-
else:
19+
def render_dots_or_parts(self, sep: Optional[str] = None):
20+
if sep is None:
2321
return self.prefixed_parts()
22+
else:
23+
return [sep.join(self.prefixed_parts())]
2424

2525

2626
class CudaVersion(MultiPartVersion):

0 commit comments

Comments
 (0)