Skip to content

Commit e545168

Browse files
bottlerfacebook-github-bot
authored andcommitted
Run tests in github action not circleci (#1896)
Summary: Pull Request resolved: #1896 Differential Revision: D65272512 Pulled By: bottler
1 parent e138482 commit e545168

File tree

3 files changed

+64
-10
lines changed

3 files changed

+64
-10
lines changed

.github/workflows/build.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: facebookresearch/pytorch3d/build_and_test
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
jobs:
7+
binary_linux_conda_cuda:
8+
runs-on: 4-core-ubuntu-gpu-t4
9+
env:
10+
PYTHON_VERSION: "3.12"
11+
BUILD_VERSION: "${{ github.run_number }}"
12+
PYTORCH_VERSION: "2.4.1"
13+
CU_VERSION: "cu121"
14+
JUST_TESTRUN: 1
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Build and run tests
18+
run: |-
19+
conda create --name env --yes --quiet conda-build
20+
conda run --no-capture-output --name env python3 ./packaging/build_conda.py --use-conda-cuda

packaging/build_conda.py

+35-10
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
#
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
6-
6+
import argparse
77
import os.path
88
import runpy
99
import subprocess
10-
from typing import List
10+
from typing import List, Tuple
1111

1212
# required env vars:
1313
# CU_VERSION: E.g. cu112
@@ -23,7 +23,7 @@
2323
source_root_dir = os.environ["PWD"]
2424

2525

26-
def version_constraint(version):
26+
def version_constraint(version) -> str:
2727
"""
2828
Given version "11.3" returns " >=11.3,<11.4"
2929
"""
@@ -32,7 +32,7 @@ def version_constraint(version):
3232
return f" >={version},<{upper}"
3333

3434

35-
def get_cuda_major_minor():
35+
def get_cuda_major_minor() -> Tuple[str, str]:
3636
if CU_VERSION == "cpu":
3737
raise ValueError("fn only for cuda builds")
3838
if len(CU_VERSION) != 5 or CU_VERSION[:2] != "cu":
@@ -42,11 +42,17 @@ def get_cuda_major_minor():
4242
return major, minor
4343

4444

45-
def setup_cuda():
45+
def setup_cuda(use_conda_cuda: bool) -> None:
4646
if CU_VERSION == "cpu":
4747
return
4848
major, minor = get_cuda_major_minor()
49-
os.environ["CUDA_HOME"] = f"/usr/local/cuda-{major}.{minor}/"
49+
if use_conda_cuda:
50+
os.environ["CONDA_CUDA_TOOLKIT_BUILD_CONSTRAINT1"] = "- cudatoolkit"
51+
os.environ["CONDA_CUDA_TOOLKIT_BUILD_CONSTRAINT2"] = (
52+
f"- cuda-version={major}.{minor}"
53+
)
54+
else:
55+
os.environ["CUDA_HOME"] = f"/usr/local/cuda-{major}.{minor}/"
5056
os.environ["FORCE_CUDA"] = "1"
5157

5258
basic_nvcc_flags = (
@@ -95,7 +101,7 @@ def setup_conda_pytorch_constraint() -> List[str]:
95101
return ["-c", "pytorch", "-c", "nvidia"]
96102

97103

98-
def setup_conda_cudatoolkit_constraint():
104+
def setup_conda_cudatoolkit_constraint() -> None:
99105
if CU_VERSION == "cpu":
100106
os.environ["CONDA_CPUONLY_FEATURE"] = "- cpuonly"
101107
os.environ["CONDA_CUDATOOLKIT_CONSTRAINT"] = ""
@@ -116,14 +122,25 @@ def setup_conda_cudatoolkit_constraint():
116122
os.environ["CONDA_CUDATOOLKIT_CONSTRAINT"] = toolkit
117123

118124

119-
def do_build(start_args: List[str]):
125+
def do_build(start_args: List[str]) -> None:
120126
args = start_args.copy()
121127

122128
test_flag = os.environ.get("TEST_FLAG")
123129
if test_flag is not None:
124130
args.append(test_flag)
125131

126-
args.extend(["-c", "bottler", "-c", "iopath", "-c", "conda-forge"])
132+
args.extend(
133+
[
134+
"-c",
135+
"bottler",
136+
"-c",
137+
"iopath",
138+
"-c",
139+
"conda-forge",
140+
"-c",
141+
"nvidia/label/cuda-12.1.0",
142+
]
143+
)
127144
args.append("--no-anaconda-upload")
128145
args.extend(["--python", os.environ["PYTHON_VERSION"]])
129146
args.append("packaging/pytorch3d")
@@ -132,8 +149,16 @@ def do_build(start_args: List[str]):
132149

133150

134151
if __name__ == "__main__":
152+
parser = argparse.ArgumentParser(description="Build the conda package.")
153+
parser.add_argument(
154+
"--use-conda-cuda",
155+
action="store_true",
156+
help="get cuda from conda ignoring local cuda",
157+
)
158+
our_args = parser.parse_args()
159+
135160
args = ["conda", "build"]
136-
setup_cuda()
161+
setup_cuda(use_conda_cuda=our_args.use_conda_cuda)
137162

138163
init_path = source_root_dir + "/pytorch3d/__init__.py"
139164
build_version = runpy.run_path(init_path)["__version__"]

packaging/pytorch3d/meta.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ source:
88
requirements:
99
build:
1010
- {{ compiler('c') }} # [win]
11+
{{ environ.get('CONDA_CUDA_TOOLKIT_BUILD_CONSTRAINT1', '') }}
12+
{{ environ.get('CONDA_CUDA_TOOLKIT_BUILD_CONSTRAINT2', '') }}
1113
{{ environ.get('CONDA_CUB_CONSTRAINT') }}
1214

1315
host:
1416
- python
17+
- mkl =2023 # [x86_64]
1518
{{ environ.get('SETUPTOOLS_CONSTRAINT') }}
1619
{{ environ.get('CONDA_PYTORCH_BUILD_CONSTRAINT') }}
1720
{{ environ.get('CONDA_PYTORCH_MKL_CONSTRAINT') }}
@@ -22,12 +25,14 @@ requirements:
2225
- python
2326
- numpy >=1.11
2427
- torchvision >=0.5
28+
- mkl =2023 # [x86_64]
2529
- iopath
2630
{{ environ.get('CONDA_PYTORCH_CONSTRAINT') }}
2731
{{ environ.get('CONDA_CUDATOOLKIT_CONSTRAINT') }}
2832

2933
build:
3034
string: py{{py}}_{{ environ['CU_VERSION'] }}_pyt{{ environ['PYTORCH_VERSION_NODOT']}}
35+
# script: LD_LIBRARY_PATH=$PREFIX/lib:$BUILD_PREFIX/lib:$LD_LIBRARY_PATH python setup.py install --single-version-externally-managed --record=record.txt # [not win]
3136
script: python setup.py install --single-version-externally-managed --record=record.txt # [not win]
3237
script_env:
3338
- CUDA_HOME
@@ -47,6 +52,10 @@ test:
4752
- imageio
4853
- hydra-core
4954
- accelerate
55+
- matplotlib
56+
- tabulate
57+
- pandas
58+
- sqlalchemy
5059
commands:
5160
#pytest .
5261
python -m unittest discover -v -s tests -t .

0 commit comments

Comments
 (0)