Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 7 additions & 27 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
NPROC: 3

jobs:
ubuntu:
permissions:
Expand All @@ -25,31 +22,14 @@ jobs:
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Setup cache
uses: actions/cache@v3
with:
# Ref: https://github.com/apache/incubator-mxnet/pull/18459/files
path: ~/.ccache
# We include the commit sha in the cache key, as new cache entries are
# only created if there is no existing entry for the key yet.
key: ${{ runner.os }}-ccache-${{ github.sha }}
# Restore any ccache cache entry, if none for
# ${{ runner.os }}-ccache-${{ github.sha }} exists.
# Common prefix will be used so that ccache can be used across commits.
restore-keys: |
${{ runner.os }}-ccache
- name: Set up Python version
uses: actions/setup-python@v5
with:
python-version: "3.12"
# Pre-installed packages: https://github.com/actions/runner-images/tree/main/images
- name: Install ccache
run: |
sudo apt-get --yes install ccache
ccache -M 2G # GitHub's total cache limit is 5GB for all OSes.
- name: Config and build
run: |
PATH=/usr/lib/ccache:$PATH
ccache -s
./ci/run_ci.sh
ccache -s
# open3d / open3d_cpu wheels link EGL for offscreen rendering (GUI=ON).
- name: Install Open3D runtime deps
run: sudo apt-get update && sudo apt-get install --yes libegl1
- name: Run Open3D-ML tests (CPU wheel)
env:
GH_TOKEN: ${{ github.token }}
run: ./ci/run_ci.sh cpu
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pip install -r requirements-tensorflow.txt
pip install -r requirements-torch.txt
# To install a compatible version of PyTorch with CUDA on Linux
pip install -r requirements-torch-cuda.txt
# To install a compatible version of PyTorch with XPU (Intel GPU) on Linux
pip install -r requirements-torch-xpu.txt
```

To test the installation use
Expand Down Expand Up @@ -420,6 +422,7 @@ For downloading these datasets visit the respective webpages and have a look at
- [Adding a new model](docs/howtos.md#adding-a-new-model)
- [Adding a new dataset](docs/howtos.md#adding-a-new-dataset)
- [Distributed training](docs/howtos.md#distributed-training)
- [Testing CPU / CUDA / XPU parity](docs/howtos.md#testing-cpu--cuda--xpu-parity)
- [Visualize and compare input data, ground truth and results in TensorBoard](docs/tensorboard.md)
- [Inference with Intel OpenVINO](docs/openvino.md)

Expand Down
136 changes: 88 additions & 48 deletions ci/run_ci.sh
Original file line number Diff line number Diff line change
@@ -1,66 +1,106 @@
#!/usr/bin/env bash
#
# Install a prebuilt Open3D wheel + Open3D-ML deps, then run tests.
#
# Usage: ./ci/run_ci.sh [cpu|cuda|xpu]
#
# cpu — open3d_cpu wheel + requirements-torch.txt
# cuda — default open3d manylinux wheel + requirements-torch-cuda.txt
# xpu — open3d_xpu wheel + requirements-torch-xpu.txt
#
# Pytest skips (parity, accelerator-only ops, missing ops) are handled in the
# test modules. See docs/howtos.md.

set -euo pipefail

NPROC=${NPROC:?'env var must be set to number of available CPUs.'}
usage() {
sed -n '2,12p' "$0" | sed 's/^# \?//'
echo
echo "Example: ./ci/run_ci.sh cpu"
exit "${1:-0}"
}

BACKEND="${1:-cpu}"
case "${BACKEND}" in
cpu | cuda | xpu) ;;
-h | --help) usage 0 ;;
*)
echo "Unknown backend: ${BACKEND}" >&2
usage 1
;;
esac

PIP_VER="24.3.1"
OPEN3D_REPO="isl-org/Open3D"
RELEASE_TAG="main-devel"
PY_TAG="cp312"

echo 1. Prepare the Open3D-ML repo and install dependencies
echo
export PATH_TO_OPEN3D_ML="$PWD"
echo "$PATH_TO_OPEN3D_ML"
# the build system of the main repo expects a main branch. make sure main exists
git checkout -b main || true
python -m pip install -U pip==$PIP_VER
python -m pip install -r requirements.txt \
-r requirements-torch.txt \
-r requirements-tensorflow.txt
# -r requirements-openvino.txt # Numpy version conflict with TF 2.8.2
cd ..
python -m pip install -U Cython
case "${BACKEND}" in
cpu)
WHEEL_GLOB="open3d_cpu-*-${PY_TAG}-${PY_TAG}-manylinux*_x86_64.whl"
TORCH_REQUIREMENTS="requirements-torch.txt"
;;
cuda)
WHEEL_GLOB="open3d-[0-9]*-${PY_TAG}-${PY_TAG}-manylinux*_x86_64.whl"
TORCH_REQUIREMENTS="requirements-torch-cuda.txt"
;;
xpu)
WHEEL_GLOB="open3d_xpu-*-${PY_TAG}-${PY_TAG}-manylinux*_x86_64.whl"
TORCH_REQUIREMENTS="requirements-torch-xpu.txt"
;;
esac

echo 2. clone Open3D and install dependencies
echo "Open3D-ML CI backend: ${BACKEND}"
echo " wheel pattern: ${WHEEL_GLOB}"
echo " torch requirements: ${TORCH_REQUIREMENTS}"
echo
git clone --branch main --depth 1 https://github.com/isl-org/Open3D.git

./Open3D/util/install_deps_ubuntu.sh assume-yes
python -m pip install -r Open3D/python/requirements.txt \
-r Open3D/python/requirements_style.txt \
-r Open3D/python/requirements_test.txt
echo "1. Download the latest Open3D devel wheel from ${OPEN3D_REPO}@${RELEASE_TAG}"
echo
gh release download "${RELEASE_TAG}" \
--repo "${OPEN3D_REPO}" \
--pattern "${WHEEL_GLOB}" \
--dir . \
--clobber
shopt -s nullglob
wheel_matches=( ${WHEEL_GLOB} )
shopt -u nullglob
if [ "${#wheel_matches[@]}" -ne 1 ]; then
echo "Expected exactly one wheel matching ${WHEEL_GLOB}, found ${#wheel_matches[@]}" >&2
exit 1
fi
WHEEL_PATH="${wheel_matches[0]}"
echo "Downloaded: ${WHEEL_PATH}"

echo 3. Configure for bundling the Open3D-ML part
echo "2. Install the wheel in a fresh virtual environment"
echo
mkdir Open3D/build
pushd Open3D/build
cmake -DBUNDLE_OPEN3D_ML=ON \
-DOPEN3D_ML_ROOT="${PATH_TO_OPEN3D_ML}" \
-DBUILD_TENSORFLOW_OPS=ON \
-DBUILD_PYTORCH_OPS=ON \
-DBUILD_GUI=ON \
-DBUILD_UNIT_TESTS=OFF \
-DBUILD_BENCHMARKS=OFF \
-DBUILD_EXAMPLES=OFF \
..
python -m venv open3d_test.venv
# shellcheck disable=SC1091
source open3d_test.venv/bin/activate
python -m pip install -U pip=="${PIP_VER}" pytest
python -m pip install "${WHEEL_PATH}"

echo 4. Build and install wheel
echo "3. Sanity-check the installed package"
echo
make -j"$NPROC" install-pip-package
python -W default -c "import open3d; print('Installed:', open3d)"

echo 5. run examples/tests in the Open3D-ML repo outside of the repo directory to
echo make sure that the installed package works.
echo "4. Install Open3D-ML dependencies"
echo
popd
mkdir test_workdir
pushd test_workdir
mv "$PATH_TO_OPEN3D_ML/tests" .
echo Add --randomly-seed=SEED to the test command to reproduce test order.
python -m pytest tests
export PATH_TO_OPEN3D_ML="$PWD"
python -m pip install -r requirements.txt -r "${TORCH_REQUIREMENTS}" \
-r requirements-tensorflow.txt

# Load ml3d from this checkout (wheel _ml3d may lag main-devel until the next Open3D release).
export OPEN3D_ML_ROOT="${PATH_TO_OPEN3D_ML}"

run_test_suite() {
echo "Running: ./tests/run_tests.sh tests"
echo "Add --randomly-seed=SEED via pytest env if reproducing order."
./tests/run_tests.sh tests
}

echo "... now do the same but in dev mode by setting OPEN3D_ML_ROOT"
echo "5. Run the Open3D-ML pytest suite (open3d wheel + ml3d from OPEN3D_ML_ROOT)"
echo
export OPEN3D_ML_ROOT="$PATH_TO_OPEN3D_ML"
echo Add --randomly-seed=SEED to the test command to reproduce test order.
python -m pytest tests
unset OPEN3D_ML_ROOT
run_test_suite

popd
deactivate
30 changes: 29 additions & 1 deletion docs/howtos.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,32 @@ Distributed training uses the PyTorch Distributed Data Parallel (DDP) module and

![PointPillars training on Waymo per epoch training time with number of GPUs](https://user-images.githubusercontent.com/41028320/220750523-57075575-8cc7-4e40-99b0-a4e79995f1ec.png)

See [`scripts/train_scripts/pointpillars_waymo.sh`](../scripts/train_scripts/pointpillars_waymo.sh) for an example SLURM training script for distributed training on two nodes, using four GPUs on each node. The remaining configuration is read from the config file [`pointpillars_waymo.yml`](../ml3d/configs/pointpillars_waymo.yml).
See [`scripts/train_scripts/pointpillars_waymo.sh`](../scripts/train_scripts/pointpillars_waymo.sh) for an example SLURM training script for distributed training on two nodes, using four GPUs on each node. The remaining configuration is read from the config file [`pointpillars_waymo.yml`](../ml3d/configs/pointpillars_waymo.yml).

## Testing CPU / CUDA / XPU parity

The PyTorch model tests in [`tests/test_models_torch.py`](../tests/test_models_torch.py) build the same model and batch on CPU and on an accelerator (CUDA or XPU), then assert that outputs and gradients match within a tolerance (see [`tests/torch_backend_parity.py`](../tests/torch_backend_parity.py)). Correctness is verified as follows:

- **CUDA**: new CUDA results are compared against the existing CPU results.
- **XPU (Intel GPU)**: new XPU results are compared against the same CPU results, using separate tolerances tuned for SYCL's op ordering.

Both accelerator paths reuse the same CPU baseline, so CPU correctness is the
common foundation both backends are checked against.

Run the full suite locally with:

```bash
./tests/run_tests.sh
# or select specific tests, e.g.
./tests/run_tests.sh tests/test_models_torch.py -k "not sparse"
```

### Note on GitHub Actions CI

GitHub-hosted runners have no NVIDIA or Intel GPU. CI runs `./ci/run_ci.sh cpu`,
which installs the `open3d_cpu` wheel and PyTorch CPU, sets `OPEN3D_ML_ROOT` to
this checkout (so model code matches the PR), then runs the full pytest tree.
Individual tests skip when an op backend or accelerator is unavailable.

Run `./ci/run_ci.sh cuda` or `./ci/run_ci.sh xpu` locally or on GPU machines to
exercise CUDA/XPU wheels and PyTorch builds.
17 changes: 17 additions & 0 deletions ml3d/metrics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import open3d


def _sycl_accelerator_available():
"""True when Open3D sees a non-CPU SYCL device (e.g. Intel GPU), not SYCL-on-CPU."""
o3c = open3d.core
if not o3c.sycl.is_available():
return False
for device in o3c.sycl.get_available_devices():
props = o3c.sycl.get_device_properties(device)
if props.device_type != "cpu":
return True
return False


if open3d.core.cuda.device_count() > 0:
# Open3D is built with CUDA and the machine has a CUDA device.
from open3d.ml.contrib import iou_bev_cuda as iou_bev
from open3d.ml.contrib import iou_3d_cuda as iou_3d
elif _sycl_accelerator_available():
# Open3D SYCL build with an accelerator-class SYCL device (not CPU-only SYCL).
from open3d.ml.contrib import iou_bev_sycl as iou_bev
from open3d.ml.contrib import iou_3d_sycl as iou_3d
else:
from open3d.ml.contrib import iou_bev_cpu as iou_bev
from open3d.ml.contrib import iou_3d_cpu as iou_3d
Expand Down
2 changes: 1 addition & 1 deletion ml3d/torch/dataloaders/concat_batcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def __init__(self, device, model='KPConv'):
"""Initialize.

Args:
device: torch device 'gpu' or 'cpu'
device: Torch device (cpu, cuda, or xpu).

Returns:
class: The corresponding class.
Expand Down
2 changes: 1 addition & 1 deletion ml3d/torch/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_loss(self, Loss, results, inputs, device):
Loss: A loss object.
results: This is the output of the model.
inputs: This is the input to the model.
device: The torch device to be used.
device: Torch device (cpu, cuda, or xpu).

Returns:
Returns the loss value.
Expand Down
6 changes: 5 additions & 1 deletion ml3d/torch/models/point_pillars.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from .base_model_objdet import BaseModel

from ...utils import MODEL
from ..utils.torch_utils import default_training_device
from ..utils.objdet_helper import Anchor3DRangeGenerator, BBoxCoder, multiclass_nms, limit_period, get_paddings_indicator, bbox_overlaps, box3d_to_bev2d
from ..modules.losses.focal_loss import FocalLoss
from ..modules.losses.smooth_L1 import SmoothL1Loss
Expand Down Expand Up @@ -60,7 +61,7 @@ class PointPillars(BaseModel):

def __init__(self,
name="PointPillars",
device="cuda",
device=None,
point_cloud_range=[0, -40.0, -3, 70.0, 40.0, 1],
classes=['car'],
voxelize={},
Expand All @@ -72,6 +73,9 @@ def __init__(self,
loss={},
**kwargs):

if device is None:
device = default_training_device()

super().__init__(name=name,
point_cloud_range=point_cloud_range,
device=device,
Expand Down
11 changes: 7 additions & 4 deletions ml3d/torch/models/point_rcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from ..modules.pointnet import Pointnet2MSG, PointnetSAModule
from ..utils.objdet_helper import xywhr_to_xyxyr
from open3d.ml.torch.ops import nms
from ..utils.torch_utils import gen_CNN
from ..utils.torch_utils import gen_CNN, default_training_device
from ...datasets.utils import BEVBox3D, DataProcessing
from ...datasets.utils.operations import points_in_box
from ...datasets.augment import ObjdetAugmentation
Expand Down Expand Up @@ -68,8 +68,8 @@ class PointRCNN(BaseModel):
Args:
name (string): Name of model.
Default to "PointRCNN".
device (string): 'cuda' or 'cpu'.
Default to 'cuda'.
device (string): 'cuda', 'xpu', or 'cpu'. Default: first available
accelerator (cuda, then xpu), else cpu.
classes (string[]): List of classes used for object detection:
Default to ['Car'].
score_thres (float): Min confindence score for prediction.
Expand All @@ -86,7 +86,7 @@ class PointRCNN(BaseModel):

def __init__(self,
name="PointRCNN",
device="cuda",
device=None,
classes=['Car'],
score_thres=0.3,
npoints=16384,
Expand All @@ -95,6 +95,9 @@ def __init__(self,
mode="RCNN",
**kwargs):

if device is None:
device = default_training_device()

super().__init__(name=name, device=device, **kwargs)
assert mode == "RPN" or mode == "RCNN"
self.mode = mode
Expand Down
9 changes: 6 additions & 3 deletions ml3d/torch/models/point_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def get_loss(self, sem_seg_loss, results, inputs, device):
sem_seg_loss: Object of type `SemSegLoss`.
results: Output of the model.
inputs: Input of the model.
device: device(cpu or cuda).
device: Torch device (cpu, cuda, or xpu).

Returns:
Returns loss, labels and scores.
Expand Down Expand Up @@ -717,6 +717,7 @@ def knn_batch(points,
if points_row_splits.shape[0] != queries_row_splits.shape[0]:
raise ValueError("KNN(points and queries must have same batch size)")

device = points.device
points = points.cpu()
queries = queries.cpu()

Expand All @@ -729,9 +730,11 @@ def knn_batch(points,
return_distances=True)
if return_distances:
return ans.neighbors_index.reshape(
-1, k).long().cuda(), ans.neighbors_distance.reshape(-1, k).cuda()
-1,
k).long().to(device), ans.neighbors_distance.reshape(-1,
k).to(device)
else:
return ans.neighbors_index.reshape(-1, k).long().cuda()
return ans.neighbors_index.reshape(-1, k).long().to(device)


def interpolation(points,
Expand Down
Loading
Loading