Skip to content

Commit 5963b94

Browse files
authored
Updates to PyTorch 2.7 (#679)
- Pytorch 2.7.1 (cxx11_abi) - CUDA 12.6 - Tensorflow 2.19.0 - Formatter updates: yapf v0.53, clang-format 18
1 parent b64b514 commit 5963b94

20 files changed

Lines changed: 89 additions & 110 deletions

.github/workflows/style.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ jobs:
1616
steps:
1717
- name: Checkout source code
1818
uses: actions/checkout@v4
19-
with:
20-
submodules: true
2119
- name: Set up Python version
2220
uses: actions/setup-python@v5
2321
with:
24-
python-version: '3.10'
22+
python-version: '3.12'
2523
- name: Install dependencies
2624
run: |
27-
python -m pip install -U clang-format==10.0.1.1 yapf==0.30.0 nbformat pydocstyle==6.0.0
25+
python -m pip install -U clang-format==18.* yapf==0.43.* nbformat==5.10.* pydocstyle==6.0.0
2826
- name: Run style check
2927
run: |
3028
python ci/check_style.py --verbose

.github/workflows/ubuntu.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ permissions: {}
44
on:
55
workflow_dispatch:
66
push:
7-
branches: [main, dev]
7+
branches: [main]
88
pull_request:
99
types: [opened, reopened, synchronize]
1010

@@ -19,7 +19,7 @@ jobs:
1919
ubuntu:
2020
permissions:
2121
contents: read
22-
runs-on: ubuntu-22.04
22+
runs-on: ubuntu-latest
2323
strategy:
2424
fail-fast: false
2525
steps:
@@ -41,7 +41,7 @@ jobs:
4141
- name: Set up Python version
4242
uses: actions/setup-python@v5
4343
with:
44-
python-version: "3.11"
44+
python-version: "3.12"
4545
# Pre-installed packages: https://github.com/actions/runner-images/tree/main/images
4646
- name: Install ccache
4747
run: |

ci/check_style.py

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,11 @@
66
from functools import partial
77
import time
88
import sys
9-
10-
# Yapf requires python 3.6+
11-
if not (sys.version_info.major == 3 and sys.version_info.minor >= 6):
12-
raise RuntimeError(
13-
"Requires Python 3.6+, currently using Python {}.{}.".format(
14-
sys.version_info.major, sys.version_info.minor))
15-
16-
# Check and import yapf
17-
# > not found: throw exception
18-
# > version mismatch: throw exception
19-
try:
20-
import yapf
21-
except:
22-
raise ImportError(
23-
"yapf not found. Install with `pip install yapf==0.30.0`.")
24-
if yapf.__version__ != "0.30.0":
25-
raise RuntimeError(
26-
"yapf 0.30.0 required. Install with `pip install yapf==0.30.0`.")
27-
print("Using yapf version {}".format(yapf.__version__))
28-
29-
# Check and import nbformat
30-
# > not found: throw exception
31-
try:
32-
import nbformat
33-
except:
34-
raise ImportError(
35-
"nbformat not found. Install with `pip install nbformat`.")
36-
print("Using nbformat version {}".format(nbformat.__version__))
9+
import yapf
10+
import nbformat
3711

3812
PYTHON_FORMAT_DIRS = ["."]
39-
4013
JUPYTER_FORMAT_DIRS = ["."]
41-
4214
# Note: also modify CPP_FORMAT_DIRS in check_cpp_style.cmake.
4315
CPP_FORMAT_DIRS = ["."]
4416

@@ -86,8 +58,8 @@ def _apply_style(file_path, style_config):
8658
style_config=style_config,
8759
in_place=True)
8860

89-
def run(self, do_apply_style, no_parallel, verbose):
90-
if do_apply_style:
61+
def run(self, apply, no_parallel, verbose):
62+
if apply:
9163
print("Applying Python style...")
9264
else:
9365
print("Checking Python style...")
@@ -112,7 +84,7 @@ def run(self, do_apply_style, no_parallel, verbose):
11284
for is_valid, file_path in zip(is_valid_files, self.file_paths):
11385
if not is_valid:
11486
changed_files.append(file_path)
115-
if do_apply_style:
87+
if apply:
11688
self._apply_style(file_path, self.style_config)
11789
print("Formatting takes {:.2f}s".format(time.time() - start_time))
11890

@@ -126,7 +98,7 @@ def __init__(self, file_paths, style_config):
12698
self.style_config = style_config
12799

128100
@staticmethod
129-
def _check_or_apply_style(file_path, style_config, do_apply_style):
101+
def _check_or_apply_style(file_path, style_config, apply):
130102
"""Returns true if style is valid.
131103
132104
Since there are common code for check and apply style, the two functions
@@ -142,27 +114,39 @@ def _check_or_apply_style(file_path, style_config, do_apply_style):
142114
if cell["cell_type"] != "code":
143115
continue
144116
src = cell["source"]
117+
if not src.strip(): # Ignore empty cells.
118+
continue
145119
lines = src.split("\n")
146-
if len(lines) <= 0 or "# noqa" in lines[0]:
120+
if "# noqa" in lines[0]:
147121
continue
122+
# Ignore cells starting with shell commands or jupyter magics.
123+
# These are not valid python code and yapf will fail.
124+
if src.lstrip().startswith(('!', '%')):
125+
continue
126+
148127
# yapf will puts a `\n` at the end of each cell, and if this is the
149128
# only change, cell_changed is still False.
150-
formatted_src, cell_changed = yapf.yapflib.yapf_api.FormatCode(
151-
src, style_config=style_config)
129+
try:
130+
formatted_src, cell_changed = yapf.yapflib.yapf_api.FormatCode(
131+
src, style_config=style_config)
132+
except Exception:
133+
# This may happen for cells with valid python and magics/shell
134+
# commands mixed. We will just ignore formatting for these cells.
135+
continue
152136
if formatted_src.endswith("\n"):
153137
formatted_src = formatted_src[:-1]
154138
if cell_changed:
155139
cell["source"] = formatted_src
156140
changed = True
157141

158-
if do_apply_style:
142+
if apply:
159143
with open(file_path, "w") as f:
160144
nbformat.write(notebook, f, version=nbformat.NO_CONVERT)
161145

162146
return not changed
163147

164-
def run(self, do_apply_style, no_parallel, verbose):
165-
if do_apply_style:
148+
def run(self, apply, no_parallel, verbose):
149+
if apply:
166150
print("Applying Jupyter style...")
167151
else:
168152
print("Checking Jupyter style...")
@@ -177,22 +161,22 @@ def run(self, do_apply_style, no_parallel, verbose):
177161
is_valid_files = map(
178162
partial(self._check_or_apply_style,
179163
style_config=self.style_config,
180-
do_apply_style=False), self.file_paths)
164+
apply=False), self.file_paths)
181165
else:
182166
with multiprocessing.Pool(multiprocessing.cpu_count()) as pool:
183167
is_valid_files = pool.map(
184168
partial(self._check_or_apply_style,
185169
style_config=self.style_config,
186-
do_apply_style=False), self.file_paths)
170+
apply=False), self.file_paths)
187171

188172
changed_files = []
189173
for is_valid, file_path in zip(is_valid_files, self.file_paths):
190174
if not is_valid:
191175
changed_files.append(file_path)
192-
if do_apply_style:
176+
if apply:
193177
self._check_or_apply_style(file_path,
194178
style_config=self.style_config,
195-
do_apply_style=True)
179+
apply=True)
196180
print("Formatting takes {:.2f}s".format(time.time() - start_time))
197181

198182
return changed_files
@@ -207,8 +191,8 @@ def run(self, do_apply_style, no_parallel, verbose):
207191

208192
parser = argparse.ArgumentParser()
209193
parser.add_argument(
210-
"--do_apply_style",
211-
dest="do_apply_style",
194+
"--apply",
195+
dest="apply",
212196
action="store_true",
213197
default=False,
214198
help="Apply style to files in-place.",
@@ -242,16 +226,16 @@ def run(self, do_apply_style, no_parallel, verbose):
242226

243227
changed_files = []
244228
changed_files.extend(
245-
python_formatter.run(do_apply_style=args.do_apply_style,
229+
python_formatter.run(apply=args.apply,
246230
no_parallel=args.no_parallel,
247231
verbose=args.verbose))
248232
changed_files.extend(
249-
jupyter_formatter.run(do_apply_style=args.do_apply_style,
233+
jupyter_formatter.run(apply=args.apply,
250234
no_parallel=args.no_parallel,
251235
verbose=args.verbose))
252236

253237
if len(changed_files) != 0:
254-
if args.do_apply_style:
238+
if args.apply:
255239
print("Style applied to the following files:")
256240
print("\n".join(changed_files))
257241
else:

ci/run_ci.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -euo pipefail
44

55
NPROC=${NPROC:?'env var must be set to number of available CPUs.'}
6-
PIP_VER="23.2.1"
6+
PIP_VER="24.3.1"
77

88
echo 1. Prepare the Open3D-ML repo and install dependencies
99
echo
@@ -13,15 +13,15 @@ echo "$PATH_TO_OPEN3D_ML"
1313
git checkout -b main || true
1414
python -m pip install -U pip==$PIP_VER
1515
python -m pip install -r requirements.txt \
16-
-r requirements-torch.txt
17-
# -r requirements-tensorflow.txt # TF disabled on Linux (Open3D PR#6288)
16+
-r requirements-torch.txt \
17+
-r requirements-tensorflow.txt
1818
# -r requirements-openvino.txt # Numpy version conflict with TF 2.8.2
1919
cd ..
2020
python -m pip install -U Cython
2121

2222
echo 2. clone Open3D and install dependencies
2323
echo
24-
git clone --branch main https://github.com/isl-org/Open3D.git
24+
git clone --branch main --depth 1 https://github.com/isl-org/Open3D.git
2525

2626
./Open3D/util/install_deps_ubuntu.sh assume-yes
2727
python -m pip install -r Open3D/python/requirements.txt \
@@ -32,11 +32,9 @@ echo 3. Configure for bundling the Open3D-ML part
3232
echo
3333
mkdir Open3D/build
3434
pushd Open3D/build
35-
# TF disabled on Linux (Open3D PR#6288)
3635
cmake -DBUNDLE_OPEN3D_ML=ON \
3736
-DOPEN3D_ML_ROOT="${PATH_TO_OPEN3D_ML}" \
38-
-DGLIBCXX_USE_CXX11_ABI=OFF \
39-
-DBUILD_TENSORFLOW_OPS=OFF \
37+
-DBUILD_TENSORFLOW_OPS=ON \
4038
-DBUILD_PYTORCH_OPS=ON \
4139
-DBUILD_GUI=ON \
4240
-DBUILD_UNIT_TESTS=OFF \

ml3d/datasets/utils/dataprocessing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@ def remove_outside_points(points, world_cam, cam_img, image_shape):
234234
pts_cam = DataProcessing.world2cam(points[:, :3], world_cam)
235235
pts_img, depth = DataProcessing.cam2img(pts_cam, cam_img)
236236

237-
val_flag_1 = np.logical_and(pts_img[:, 0] >= 0,
238-
pts_img[:, 0] < image_shape[1])
239-
val_flag_2 = np.logical_and(pts_img[:, 1] >= 0,
240-
pts_img[:, 1] < image_shape[0])
237+
val_flag_1 = np.logical_and(pts_img[:, 0] >= 0, pts_img[:, 0]
238+
< image_shape[1])
239+
val_flag_2 = np.logical_and(pts_img[:, 1] >= 0, pts_img[:, 1]
240+
< image_shape[0])
241241
val_flag_merge = np.logical_and(val_flag_1, val_flag_2)
242242
valid = np.logical_and(val_flag_merge, depth >= 0)
243243

ml3d/metrics/mAP.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ def precision_3d(pred,
108108
axis=1).astype("float32")
109109

110110
# identify all matches (filtered preds vs filtered targets)
111-
match_cond = np.any(
112-
overlap_label[pred_idx][:, target_idx] >= min_overlap[i],
113-
axis=-1)
111+
match_cond = np.any(overlap_label[pred_idx][:, target_idx]
112+
>= min_overlap[i],
113+
axis=-1)
114114
tp = np.zeros((len(pred_idx),))
115115

116116
# all matches first fp

ml3d/tf/dataloaders/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Dataloader for TensorFlow."""
22

33
from .tf_dataloader import TFDataloader
4+
45
__all__ = ['TFDataloader']

ml3d/tf/models/point_pillars.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ def preprocess(self, data, attr):
242242
max_val = np.array(self.point_cloud_range[3:])
243243

244244
points = points[np.where(
245-
np.all(np.logical_and(points[:, :3] >= min_val,
246-
points[:, :3] < max_val),
245+
np.all(np.logical_and(points[:, :3] >= min_val, points[:, :3]
246+
< max_val),
247247
axis=-1))]
248248

249249
data['point'] = points
@@ -264,8 +264,8 @@ def preprocess(self, data, attr):
264264
max_val = np.array(self.point_cloud_range[3:])
265265

266266
points = points[np.where(
267-
np.all(np.logical_and(points[:, :3] >= min_val,
268-
points[:, :3] < max_val),
267+
np.all(np.logical_and(points[:, :3] >= min_val, points[:, :3]
268+
< max_val),
269269
axis=-1))]
270270

271271
new_data['full_point'] = points

ml3d/tf/models/point_rcnn.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ def batcher():
388388
for lab in labels:
389389
max_lab = max(max_lab, lab.shape[0])
390390

391-
if 'labels' in batch[
392-
0] and labels[0].shape[0] != points.shape[1]:
391+
if 'labels' in batch[0] and labels[0].shape[0] != points.shape[
392+
1]:
393393
pad_labels = np.ones(
394394
(len(labels), max_lab), dtype=np.int32) * (-1)
395395
for j in range(len(labels)):
@@ -774,8 +774,8 @@ def __init__(
774774
self.SA_modules = []
775775
for i in range(len(SA_config["npoints"])):
776776
mlps = [in_channels] + SA_config["mlps"][i]
777-
npoint = SA_config["npoints"][
778-
i] if SA_config["npoints"][i] != -1 else None
777+
npoint = SA_config["npoints"][i] if SA_config["npoints"][
778+
i] != -1 else None
779779
self.SA_modules.append(
780780
PointnetSAModule(npoint=npoint,
781781
radius=SA_config["radius"][i],

ml3d/tf/models/pvcnn.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ def preprocess(self, data, attr):
177177

178178
feat = np.concatenate([x, y, z, feat, norm_x, norm_y, norm_z], axis=-1)
179179

180-
choices = np.random.choice(
181-
points.shape[0],
182-
self.cfg.num_points,
183-
replace=(points.shape[0] < self.cfg.num_points))
180+
choices = np.random.choice(points.shape[0],
181+
self.cfg.num_points,
182+
replace=(points.shape[0]
183+
< self.cfg.num_points))
184184
points = points[choices]
185185
feat = feat[choices]
186186
labels = labels[choices]

0 commit comments

Comments
 (0)