test fixes

Summary: Some random seed changes. Skip multigpu tests when there's only one gpu. This is a better fix for what AI is doing in D80600882.

Reviewed By: MichaelRamamonjisoa

Differential Revision: D80625966

fbshipit-source-id: ac3952e7144125fd3a05ad6e4e6e5976ae10a8ef
This commit is contained in:
Jeremy Reizenstein 2025-08-27 06:55:50 -07:00 committed by Facebook GitHub Bot
parent 50f8efa1cb
commit dd068703d1
8 changed files with 17 additions and 8 deletions

View File

@ -10,7 +10,7 @@
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DIR=$(dirname "${DIR}")
if [[ -f "${DIR}/TARGETS" ]]
if [[ -f "${DIR}/BUCK" ]]
then
pyfmt "${DIR}"
else

View File

@ -134,7 +134,7 @@ if os.getenv("PYTORCH3D_NO_NINJA", "0") == "1":
class BuildExtension(torch.utils.cpp_extension.BuildExtension):
def __init__(self, *args, **kwargs):
super().__init__(use_ninja=False, *args, **kwargs)
super().__init__(*args, use_ninja=False, **kwargs)
else:
BuildExtension = torch.utils.cpp_extension.BuildExtension

View File

@ -31,6 +31,13 @@ def skip_opengl_requested() -> bool:
usesOpengl = unittest.skipIf(skip_opengl_requested(), "uses opengl")
def have_multiple_gpus() -> bool:
return torch.cuda.device_count() > 1
needs_multigpu = unittest.skipIf(not have_multiple_gpus(), "needs multiple GPUs")
def get_tests_dir() -> Path:
"""
Returns Path for the directory containing this file.

View File

@ -72,6 +72,7 @@ class TestKNN(TestCaseMixin, unittest.TestCase):
factors = [Ns, Ds, P1s, P2s, Ks, norms]
for N, D, P1, P2, K, norm in product(*factors):
for version in versions:
torch.manual_seed(2)
if version == 3 and K > 4:
continue
x = torch.randn(N, P1, D, device=device, requires_grad=True)

View File

@ -17,7 +17,7 @@ from pytorch3d.structures.pointclouds import (
Pointclouds,
)
from .common_testing import TestCaseMixin
from .common_testing import needs_multigpu, TestCaseMixin
class TestPointclouds(TestCaseMixin, unittest.TestCase):
@ -703,6 +703,7 @@ class TestPointclouds(TestCaseMixin, unittest.TestCase):
self.assertEqual(cuda_device, cloud.device)
self.assertIsNot(cloud, converted_cloud)
@needs_multigpu
def test_to_list(self):
cloud = self.init_cloud(5, 100, 10)
device = torch.device("cuda:1")
@ -740,6 +741,7 @@ class TestPointclouds(TestCaseMixin, unittest.TestCase):
self.assertTrue(cloud._P == new_cloud._P)
self.assertTrue(cloud._C == new_cloud._C)
@needs_multigpu
def test_to_tensor(self):
cloud = self.init_cloud(5, 100, 10, lists_to_tensors=True)
device = torch.device("cuda:1")

View File

@ -165,7 +165,7 @@ class TestICP(TestCaseMixin, unittest.TestCase):
a set of randomly-sized Pointclouds and on their padded versions.
"""
torch.manual_seed(4)
torch.manual_seed(14)
device = torch.device("cuda:0")
for estimate_scale in (True, False):

View File

@ -29,7 +29,7 @@ from pytorch3d.renderer.opengl import MeshRasterizerOpenGL
from pytorch3d.structures import Meshes, Pointclouds
from pytorch3d.utils.ico_sphere import ico_sphere
from .common_testing import TestCaseMixin, usesOpengl
from .common_testing import needs_multigpu, TestCaseMixin, usesOpengl
# Set the number of GPUS you want to test with
@ -116,6 +116,7 @@ class TestRenderMeshesMultiGPU(TestCaseMixin, unittest.TestCase):
output_images = renderer(mesh)
self.assertEqual(output_images.device, device2)
@needs_multigpu
def test_mesh_renderer_to(self):
self._mesh_renderer_to(MeshRasterizer, SoftPhongShader)
@ -173,6 +174,7 @@ class TestRenderMeshesMultiGPU(TestCaseMixin, unittest.TestCase):
for _ in range(100):
model(verts, texs)
@needs_multigpu
def test_render_meshes(self):
self._render_meshes(MeshRasterizer, HardGouraudShader)

View File

@ -63,9 +63,6 @@ class TestTensorProperties(TestCaseMixin, unittest.TestCase):
self.assertEqual(example_gpu.device.type, "cuda")
self.assertIsNotNone(example_gpu.device.index)
example_gpu1 = example.cuda(1)
self.assertEqual(example_gpu1.device, torch.device("cuda:1"))
def test_clone(self):
# Check clone method
example = TensorPropertiesTestClass(x=10.0, y=(100.0, 200.0))