mirror of
				https://github.com/facebookresearch/pytorch3d.git
				synced 2025-11-04 18:02:14 +08:00 
			
		
		
		
	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:
		
							parent
							
								
									50f8efa1cb
								
							
						
					
					
						commit
						dd068703d1
					
				@ -10,7 +10,7 @@
 | 
				
			|||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
 | 
					DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
 | 
				
			||||||
DIR=$(dirname "${DIR}")
 | 
					DIR=$(dirname "${DIR}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [[ -f "${DIR}/TARGETS" ]]
 | 
					if [[ -f "${DIR}/BUCK" ]]
 | 
				
			||||||
then
 | 
					then
 | 
				
			||||||
  pyfmt "${DIR}"
 | 
					  pyfmt "${DIR}"
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								setup.py
									
									
									
									
									
								
							@ -134,7 +134,7 @@ if os.getenv("PYTORCH3D_NO_NINJA", "0") == "1":
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    class BuildExtension(torch.utils.cpp_extension.BuildExtension):
 | 
					    class BuildExtension(torch.utils.cpp_extension.BuildExtension):
 | 
				
			||||||
        def __init__(self, *args, **kwargs):
 | 
					        def __init__(self, *args, **kwargs):
 | 
				
			||||||
            super().__init__(use_ninja=False, *args, **kwargs)
 | 
					            super().__init__(*args, use_ninja=False, **kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
else:
 | 
					else:
 | 
				
			||||||
    BuildExtension = torch.utils.cpp_extension.BuildExtension
 | 
					    BuildExtension = torch.utils.cpp_extension.BuildExtension
 | 
				
			||||||
 | 
				
			|||||||
@ -31,6 +31,13 @@ def skip_opengl_requested() -> bool:
 | 
				
			|||||||
usesOpengl = unittest.skipIf(skip_opengl_requested(), "uses opengl")
 | 
					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:
 | 
					def get_tests_dir() -> Path:
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    Returns Path for the directory containing this file.
 | 
					    Returns Path for the directory containing this file.
 | 
				
			||||||
 | 
				
			|||||||
@ -72,6 +72,7 @@ class TestKNN(TestCaseMixin, unittest.TestCase):
 | 
				
			|||||||
        factors = [Ns, Ds, P1s, P2s, Ks, norms]
 | 
					        factors = [Ns, Ds, P1s, P2s, Ks, norms]
 | 
				
			||||||
        for N, D, P1, P2, K, norm in product(*factors):
 | 
					        for N, D, P1, P2, K, norm in product(*factors):
 | 
				
			||||||
            for version in versions:
 | 
					            for version in versions:
 | 
				
			||||||
 | 
					                torch.manual_seed(2)
 | 
				
			||||||
                if version == 3 and K > 4:
 | 
					                if version == 3 and K > 4:
 | 
				
			||||||
                    continue
 | 
					                    continue
 | 
				
			||||||
                x = torch.randn(N, P1, D, device=device, requires_grad=True)
 | 
					                x = torch.randn(N, P1, D, device=device, requires_grad=True)
 | 
				
			||||||
 | 
				
			|||||||
@ -17,7 +17,7 @@ from pytorch3d.structures.pointclouds import (
 | 
				
			|||||||
    Pointclouds,
 | 
					    Pointclouds,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .common_testing import TestCaseMixin
 | 
					from .common_testing import needs_multigpu, TestCaseMixin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestPointclouds(TestCaseMixin, unittest.TestCase):
 | 
					class TestPointclouds(TestCaseMixin, unittest.TestCase):
 | 
				
			||||||
@ -703,6 +703,7 @@ class TestPointclouds(TestCaseMixin, unittest.TestCase):
 | 
				
			|||||||
        self.assertEqual(cuda_device, cloud.device)
 | 
					        self.assertEqual(cuda_device, cloud.device)
 | 
				
			||||||
        self.assertIsNot(cloud, converted_cloud)
 | 
					        self.assertIsNot(cloud, converted_cloud)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @needs_multigpu
 | 
				
			||||||
    def test_to_list(self):
 | 
					    def test_to_list(self):
 | 
				
			||||||
        cloud = self.init_cloud(5, 100, 10)
 | 
					        cloud = self.init_cloud(5, 100, 10)
 | 
				
			||||||
        device = torch.device("cuda:1")
 | 
					        device = torch.device("cuda:1")
 | 
				
			||||||
@ -740,6 +741,7 @@ class TestPointclouds(TestCaseMixin, unittest.TestCase):
 | 
				
			|||||||
        self.assertTrue(cloud._P == new_cloud._P)
 | 
					        self.assertTrue(cloud._P == new_cloud._P)
 | 
				
			||||||
        self.assertTrue(cloud._C == new_cloud._C)
 | 
					        self.assertTrue(cloud._C == new_cloud._C)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @needs_multigpu
 | 
				
			||||||
    def test_to_tensor(self):
 | 
					    def test_to_tensor(self):
 | 
				
			||||||
        cloud = self.init_cloud(5, 100, 10, lists_to_tensors=True)
 | 
					        cloud = self.init_cloud(5, 100, 10, lists_to_tensors=True)
 | 
				
			||||||
        device = torch.device("cuda:1")
 | 
					        device = torch.device("cuda:1")
 | 
				
			||||||
 | 
				
			|||||||
@ -165,7 +165,7 @@ class TestICP(TestCaseMixin, unittest.TestCase):
 | 
				
			|||||||
        a set of randomly-sized Pointclouds and on their padded versions.
 | 
					        a set of randomly-sized Pointclouds and on their padded versions.
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        torch.manual_seed(4)
 | 
					        torch.manual_seed(14)
 | 
				
			||||||
        device = torch.device("cuda:0")
 | 
					        device = torch.device("cuda:0")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for estimate_scale in (True, False):
 | 
					        for estimate_scale in (True, False):
 | 
				
			||||||
 | 
				
			|||||||
@ -29,7 +29,7 @@ from pytorch3d.renderer.opengl import MeshRasterizerOpenGL
 | 
				
			|||||||
from pytorch3d.structures import Meshes, Pointclouds
 | 
					from pytorch3d.structures import Meshes, Pointclouds
 | 
				
			||||||
from pytorch3d.utils.ico_sphere import ico_sphere
 | 
					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
 | 
					# Set the number of GPUS you want to test with
 | 
				
			||||||
@ -116,6 +116,7 @@ class TestRenderMeshesMultiGPU(TestCaseMixin, unittest.TestCase):
 | 
				
			|||||||
        output_images = renderer(mesh)
 | 
					        output_images = renderer(mesh)
 | 
				
			||||||
        self.assertEqual(output_images.device, device2)
 | 
					        self.assertEqual(output_images.device, device2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @needs_multigpu
 | 
				
			||||||
    def test_mesh_renderer_to(self):
 | 
					    def test_mesh_renderer_to(self):
 | 
				
			||||||
        self._mesh_renderer_to(MeshRasterizer, SoftPhongShader)
 | 
					        self._mesh_renderer_to(MeshRasterizer, SoftPhongShader)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -173,6 +174,7 @@ class TestRenderMeshesMultiGPU(TestCaseMixin, unittest.TestCase):
 | 
				
			|||||||
        for _ in range(100):
 | 
					        for _ in range(100):
 | 
				
			||||||
            model(verts, texs)
 | 
					            model(verts, texs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @needs_multigpu
 | 
				
			||||||
    def test_render_meshes(self):
 | 
					    def test_render_meshes(self):
 | 
				
			||||||
        self._render_meshes(MeshRasterizer, HardGouraudShader)
 | 
					        self._render_meshes(MeshRasterizer, HardGouraudShader)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -63,9 +63,6 @@ class TestTensorProperties(TestCaseMixin, unittest.TestCase):
 | 
				
			|||||||
        self.assertEqual(example_gpu.device.type, "cuda")
 | 
					        self.assertEqual(example_gpu.device.type, "cuda")
 | 
				
			||||||
        self.assertIsNotNone(example_gpu.device.index)
 | 
					        self.assertIsNotNone(example_gpu.device.index)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        example_gpu1 = example.cuda(1)
 | 
					 | 
				
			||||||
        self.assertEqual(example_gpu1.device, torch.device("cuda:1"))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_clone(self):
 | 
					    def test_clone(self):
 | 
				
			||||||
        # Check clone method
 | 
					        # Check clone method
 | 
				
			||||||
        example = TensorPropertiesTestClass(x=10.0, y=(100.0, 200.0))
 | 
					        example = TensorPropertiesTestClass(x=10.0, y=(100.0, 200.0))
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user