Skip to content

Commit e20cbe9

Browse files
bottlerfacebook-github-bot
authored andcommitted
test fixes and lints
Summary: - followup recent pyre change D63415925 - make tests remove temporary files - weights_only=True in torch.load - lint fixes 3 test fixes from VRehnberg in #1914 - imageio channels fix - frozen decorator in test_config - load_blobs positional Reviewed By: MichaelRamamonjisoa Differential Revision: D66162167 fbshipit-source-id: 7737e174691b62f1708443a4fae07343cec5bfeb
1 parent c17e6f9 commit e20cbe9

File tree

21 files changed

+48
-45
lines changed

21 files changed

+48
-45
lines changed

dev/linter.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ then
3636

3737
echo "Running pyre..."
3838
echo "To restart/kill pyre server, run 'pyre restart' or 'pyre kill' in fbcode/"
39-
( cd ~/fbsource/fbcode; pyre -l vision/fair/pytorch3d/ )
39+
( cd ~/fbsource/fbcode; arc pyre check //vision/fair/pytorch3d/... )
4040
fi

packaging/pytorch3d/meta.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ requirements:
3232

3333
build:
3434
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]
3635
script: python setup.py install --single-version-externally-managed --record=record.txt # [not win]
3736
script_env:
3837
- CUDA_HOME
@@ -57,7 +56,6 @@ test:
5756
- pandas
5857
- sqlalchemy
5958
commands:
60-
#pytest .
6159
python -m unittest discover -v -s tests -t .
6260

6361

projects/implicitron_trainer/impl/model_factory.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ def __call__(
116116
"cuda:%d" % 0: "cuda:%d" % accelerator.local_process_index
117117
}
118118
model_state_dict = torch.load(
119-
model_io.get_model_path(model_path), map_location=map_location
119+
model_io.get_model_path(model_path),
120+
map_location=map_location,
121+
weights_only=True,
120122
)
121123

122124
try:

projects/implicitron_trainer/impl/optimizer_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def _get_optimizer_state(
241241
map_location = {
242242
"cuda:%d" % 0: "cuda:%d" % accelerator.local_process_index
243243
}
244-
optimizer_state = torch.load(opt_path, map_location)
244+
optimizer_state = torch.load(opt_path, map_location, weights_only=True)
245245
else:
246246
raise FileNotFoundError(f"Optimizer state {opt_path} does not exist.")
247247
return optimizer_state

projects/nerf/nerf/dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ def get_nerf_datasets(
8484

8585
if autodownload and any(not os.path.isfile(p) for p in (cameras_path, image_path)):
8686
# Automatically download the data files if missing.
87-
download_data((dataset_name,), data_root=data_root)
87+
download_data([dataset_name], data_root=data_root)
8888

89-
train_data = torch.load(cameras_path)
89+
train_data = torch.load(cameras_path, weights_only=True)
9090
n_cameras = train_data["cameras"]["R"].shape[0]
9191

9292
_image_max_image_pixels = Image.MAX_IMAGE_PIXELS

projects/nerf/test_nerf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def main(cfg: DictConfig):
6363
raise ValueError(f"Model checkpoint {checkpoint_path} does not exist!")
6464

6565
print(f"Loading checkpoint {checkpoint_path}.")
66-
loaded_data = torch.load(checkpoint_path)
66+
loaded_data = torch.load(checkpoint_path, weights_only=True)
6767
# Do not load the cached xy grid.
6868
# - this allows setting an arbitrary evaluation image size.
6969
state_dict = {

projects/nerf/train_nerf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def main(cfg: DictConfig):
7777
# Resume training if requested.
7878
if cfg.resume and os.path.isfile(checkpoint_path):
7979
print(f"Resuming from checkpoint {checkpoint_path}.")
80-
loaded_data = torch.load(checkpoint_path)
80+
loaded_data = torch.load(checkpoint_path, weights_only=True)
8181
model.load_state_dict(loaded_data["model"])
8282
stats = pickle.loads(loaded_data["stats"])
8383
print(f" => resuming from epoch {stats.epoch}.")

pytorch3d/implicitron/models/feature_extractor/resnet_feature_extractor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __post_init__(self):
106106
self.layers = torch.nn.ModuleList()
107107
self.proj_layers = torch.nn.ModuleList()
108108
for stage in range(self.max_stage):
109-
stage_name = f"layer{stage+1}"
109+
stage_name = f"layer{stage + 1}"
110110
feature_name = self._get_resnet_stage_feature_name(stage)
111111
if (stage + 1) in self.stages:
112112
if (
@@ -139,7 +139,7 @@ def __post_init__(self):
139139
self.stages = set(self.stages) # convert to set for faster "in"
140140

141141
def _get_resnet_stage_feature_name(self, stage) -> str:
142-
return f"res_layer_{stage+1}"
142+
return f"res_layer_{stage + 1}"
143143

144144
def _resnet_normalize_image(self, img: torch.Tensor) -> torch.Tensor:
145145
return (img - self._resnet_mean) / self._resnet_std

pytorch3d/implicitron/tools/model_io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ def load_model(fl, map_location: Optional[dict]):
111111
flstats = get_stats_path(fl)
112112
flmodel = get_model_path(fl)
113113
flopt = get_optimizer_path(fl)
114-
model_state_dict = torch.load(flmodel, map_location=map_location)
114+
model_state_dict = torch.load(flmodel, map_location=map_location, weights_only=True)
115115
stats = load_stats(flstats)
116116
if os.path.isfile(flopt):
117-
optimizer = torch.load(flopt, map_location=map_location)
117+
optimizer = torch.load(flopt, map_location=map_location, weights_only=True)
118118
else:
119119
optimizer = None
120120

pytorch3d/io/experimental_gltf_io.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,8 @@ def _read_chunks(
163163
if binary_data is not None:
164164
binary_data = np.frombuffer(binary_data, dtype=np.uint8)
165165

166-
# pyre-fixme[7]: Expected `Optional[Tuple[Dict[str, typing.Any],
167-
# ndarray[typing.Any, typing.Any]]]` but got `Tuple[typing.Any,
168-
# Optional[ndarray[typing.Any, dtype[typing.Any]]]]`.
166+
assert binary_data is not None
167+
169168
return json_data, binary_data
170169

171170

0 commit comments

Comments
 (0)