regenerate.py 3.83 KB
Newer Older
facebook-github-bot's avatar
facebook-github-bot committed
1
2
3
4
5
6
7
8
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.

"""
This script is adapted from the torchvision one.
"""

import os.path
9

facebook-github-bot's avatar
facebook-github-bot committed
10
11
12
13
import jinja2
import yaml


Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
14
15
16
17
18
19
20
21
# The CUDA versions which have pytorch conda packages available for linux for each
# version of pytorch.
CONDA_CUDA_VERSIONS = {
    "1.4": ["cu92", "cu100", "cu101"],
    "1.5": ["cu92", "cu101", "cu102"],
}


facebook-github-bot's avatar
facebook-github-bot committed
22
23
24
25
def workflows(prefix="", filter_branch=None, upload=False, indentation=6):
    w = []
    for btype in ["conda"]:
        for python_version in ["3.6", "3.7", "3.8"]:
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
26
27
28
29
30
31
32
33
34
35
36
            for pytorch_version in ["1.4", "1.5"]:
                for cu_version in CONDA_CUDA_VERSIONS[pytorch_version]:
                    w += workflow_pair(
                        btype=btype,
                        python_version=python_version,
                        pytorch_version=pytorch_version,
                        cu_version=cu_version,
                        prefix=prefix,
                        upload=upload,
                        filter_branch=filter_branch,
                    )
37
38
39
40
41
42
    for btype in ["wheel"]:
        for python_version in ["3.6", "3.7", "3.8"]:
            for cu_version in ["cpu"]:
                w += workflow_pair(
                    btype=btype,
                    python_version=python_version,
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
43
                    pytorch_version="1.5",
44
45
46
47
48
                    cu_version=cu_version,
                    prefix=prefix,
                    upload=upload,
                    filter_branch=filter_branch,
                )
facebook-github-bot's avatar
facebook-github-bot committed
49
50
51
52
53

    return indent(indentation, w)


def workflow_pair(
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
54
55
56
57
58
59
60
61
    *,
    btype,
    python_version,
    pytorch_version,
    cu_version,
    prefix="",
    upload=False,
    filter_branch,
facebook-github-bot's avatar
facebook-github-bot committed
62
63
64
):

    w = []
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
65
66
67
    py = python_version.replace(".", "")
    pyt = pytorch_version.replace(".", "")
    base_workflow_name = f"{prefix}linux_{btype}_py{py}_{cu_version}_pyt{pyt}"
facebook-github-bot's avatar
facebook-github-bot committed
68
69
70
71
72

    w.append(
        generate_base_workflow(
            base_workflow_name=base_workflow_name,
            python_version=python_version,
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
73
            pytorch_version=pytorch_version,
facebook-github-bot's avatar
facebook-github-bot committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
            cu_version=cu_version,
            btype=btype,
            filter_branch=filter_branch,
        )
    )

    if upload:
        w.append(
            generate_upload_workflow(
                base_workflow_name=base_workflow_name,
                btype=btype,
                cu_version=cu_version,
                filter_branch=filter_branch,
            )
        )

    return w


def generate_base_workflow(
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
94
95
96
97
98
99
100
    *,
    base_workflow_name,
    python_version,
    cu_version,
    pytorch_version,
    btype,
    filter_branch=None,
facebook-github-bot's avatar
facebook-github-bot committed
101
102
103
104
105
106
):

    d = {
        "name": base_workflow_name,
        "python_version": python_version,
        "cu_version": cu_version,
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
107
        "pytorch_version": pytorch_version,
facebook-github-bot's avatar
facebook-github-bot committed
108
109
110
111
112
113
114
115
    }

    if filter_branch is not None:
        d["filters"] = {"branches": {"only": filter_branch}}

    return {f"binary_linux_{btype}": d}


116
def generate_upload_workflow(*, base_workflow_name, btype, cu_version, filter_branch):
facebook-github-bot's avatar
facebook-github-bot committed
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
    d = {
        "name": f"{base_workflow_name}_upload",
        "context": "org-member",
        "requires": [base_workflow_name],
    }

    if btype == "wheel":
        d["subfolder"] = cu_version + "/"

    if filter_branch is not None:
        d["filters"] = {"branches": {"only": filter_branch}}

    return {f"binary_{btype}_upload": d}


def indent(indentation, data_list):
    return ("\n" + " " * indentation).join(
        yaml.dump(data_list, default_flow_style=False).splitlines()
    )


if __name__ == "__main__":
    d = os.path.dirname(__file__)
    env = jinja2.Environment(
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
141
142
143
144
        loader=jinja2.FileSystemLoader(d),
        lstrip_blocks=True,
        autoescape=False,
        keep_trailing_newline=True,
facebook-github-bot's avatar
facebook-github-bot committed
145
146
147
148
    )

    with open(os.path.join(d, "config.yml"), "w") as f:
        f.write(env.get_template("config.in.yml").render(workflows=workflows))