Skip to content

Commit

Permalink
Run tests in github action not circleci (#1896)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #1896

Differential Revision: D65272512

Pulled By: bottler
  • Loading branch information
bottler authored and facebook-github-bot committed Oct 31, 2024
1 parent e138482 commit d68ec15
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 11 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: facebookresearch/pytorch3d/build_and_test
on:
pull_request:
branches:
- main
jobs:
binary_linux_conda_cuda:
runs-on: 4-core-ubuntu-gpu-t4
env:
PYTHON_VERSION: "3.12"
BUILD_VERSION: "${{ github.run_number }}"
PYTORCH_VERSION: "2.4.1"
CU_VERSION: "cu121"
JUST_TESTRUN: 1
steps:
- uses: actions/checkout@v4
- name: Build and run tests
run: |-
conda create --name env --yes --quiet conda-build
conda run --no-capture-output --name env python3 ./packaging/build_conda.py --use-conda-cuda
45 changes: 35 additions & 10 deletions packaging/build_conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

import argparse
import os.path
import runpy
import subprocess
from typing import List
from typing import List, Tuple

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


def version_constraint(version):
def version_constraint(version) -> str:
"""
Given version "11.3" returns " >=11.3,<11.4"
"""
Expand All @@ -32,7 +32,7 @@ def version_constraint(version):
return f" >={version},<{upper}"


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


def setup_cuda():
def setup_cuda(use_conda_cuda: bool) -> None:
if CU_VERSION == "cpu":
return
major, minor = get_cuda_major_minor()
os.environ["CUDA_HOME"] = f"/usr/local/cuda-{major}.{minor}/"
if use_conda_cuda:
os.environ["CONDA_CUDA_TOOLKIT_BUILD_CONSTRAINT1"] = "- cudatoolkit"
os.environ["CONDA_CUDA_TOOLKIT_BUILD_CONSTRAINT2"] = (
f"- cuda-version={major}.{minor}"
)
else:
os.environ["CUDA_HOME"] = f"/usr/local/cuda-{major}.{minor}/"
os.environ["FORCE_CUDA"] = "1"

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


def setup_conda_cudatoolkit_constraint():
def setup_conda_cudatoolkit_constraint() -> None:
if CU_VERSION == "cpu":
os.environ["CONDA_CPUONLY_FEATURE"] = "- cpuonly"
os.environ["CONDA_CUDATOOLKIT_CONSTRAINT"] = ""
Expand All @@ -116,14 +122,25 @@ def setup_conda_cudatoolkit_constraint():
os.environ["CONDA_CUDATOOLKIT_CONSTRAINT"] = toolkit


def do_build(start_args: List[str]):
def do_build(start_args: List[str]) -> None:
args = start_args.copy()

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

args.extend(["-c", "bottler", "-c", "iopath", "-c", "conda-forge"])
args.extend(
[
"-c",
"bottler",
"-c",
"iopath",
"-c",
"conda-forge",
"-c",
"nvidia/label/cuda-12.1.0",
]
)
args.append("--no-anaconda-upload")
args.extend(["--python", os.environ["PYTHON_VERSION"]])
args.append("packaging/pytorch3d")
Expand All @@ -132,8 +149,16 @@ def do_build(start_args: List[str]):


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Build the conda package.")
parser.add_argument(
"--use-conda-cuda",
action="store_true",
help="get cuda from conda ignoring local cuda",
)
our_args = parser.parse_args()

args = ["conda", "build"]
setup_cuda()
setup_cuda(use_conda_cuda=our_args.use_conda_cuda)

init_path = source_root_dir + "/pytorch3d/__init__.py"
build_version = runpy.run_path(init_path)["__version__"]
Expand Down
10 changes: 9 additions & 1 deletion packaging/pytorch3d/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ source:
requirements:
build:
- {{ compiler('c') }} # [win]
{{ environ.get('CONDA_CUDA_TOOLKIT_BUILD_CONSTRAINT1', '') }}
{{ environ.get('CONDA_CUDA_TOOLKIT_BUILD_CONSTRAINT2', '') }}
{{ environ.get('CONDA_CUB_CONSTRAINT') }}

host:
- python
- mkl =2023 # [x86_64]
{{ environ.get('SETUPTOOLS_CONSTRAINT') }}
{{ environ.get('CONDA_PYTORCH_BUILD_CONSTRAINT') }}
{{ environ.get('CONDA_PYTORCH_MKL_CONSTRAINT') }}
Expand All @@ -22,13 +25,14 @@ requirements:
- python
- numpy >=1.11
- torchvision >=0.5
- mkl =2023 # [x86_64]
- iopath
{{ environ.get('CONDA_PYTORCH_CONSTRAINT') }}
{{ environ.get('CONDA_CUDATOOLKIT_CONSTRAINT') }}

build:
string: py{{py}}_{{ environ['CU_VERSION'] }}_pyt{{ environ['PYTORCH_VERSION_NODOT']}}
script: python setup.py install --single-version-externally-managed --record=record.txt # [not win]
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]
script_env:
- CUDA_HOME
- FORCE_CUDA
Expand All @@ -47,6 +51,10 @@ test:
- imageio
- hydra-core
- accelerate
- matplotlib
- tabulate
- pandas
- sqlalchemy
commands:
#pytest .
python -m unittest discover -v -s tests -t .
Expand Down

0 comments on commit d68ec15

Please sign in to comment.