Simplify conditional code (#39781)

* Use !=

Signed-off-by: cyy <cyyever@outlook.com>

* Use get

Signed-off-by: cyy <cyyever@outlook.com>

* Format

* Simplify bool operations

Signed-off-by: cyy <cyyever@outlook.com>

---------

Signed-off-by: cyy <cyyever@outlook.com>
This commit is contained in:
Yuanyuan Chen
2025-07-30 20:32:10 +08:00
committed by GitHub
parent b94929eb49
commit 1e0665a191
172 changed files with 229 additions and 297 deletions

View File

@@ -147,7 +147,7 @@ class DepthAnythingModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.Tes
test_resize_embeddings = False
test_head_masking = False
test_torch_exportable = True
test_torch_exportable_strictly = not get_torch_major_and_minor_version() == "2.7"
test_torch_exportable_strictly = get_torch_major_and_minor_version() != "2.7"
def setUp(self):
self.model_tester = DepthAnythingModelTester(self)

View File

@@ -141,7 +141,7 @@ class DPTModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase):
test_resize_embeddings = False
test_head_masking = False
test_torch_exportable = True
test_torch_exportable_strictly = not get_torch_major_and_minor_version() == "2.7"
test_torch_exportable_strictly = get_torch_major_and_minor_version() != "2.7"
def setUp(self):
self.model_tester = DPTModelTester(self)

View File

@@ -371,7 +371,7 @@ class HieraModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase):
[num_patches, self.model_tester.embed_dim],
)
if not model_class.__name__ == "HieraBackbone":
if model_class.__name__ != "HieraBackbone":
reshaped_hidden_states = outputs.reshaped_hidden_states
self.assertEqual(len(reshaped_hidden_states), expected_num_layers)

View File

@@ -382,7 +382,7 @@ class SwinModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase):
[num_patches, self.model_tester.embed_dim],
)
if not model_class.__name__ == "SwinBackbone":
if model_class.__name__ != "SwinBackbone":
reshaped_hidden_states = outputs.reshaped_hidden_states
self.assertEqual(len(reshaped_hidden_states), expected_num_layers)

View File

@@ -365,7 +365,7 @@ class Swinv2ModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase):
[num_patches, self.model_tester.embed_dim],
)
if not model_class.__name__ == "Swinv2Backbone":
if model_class.__name__ != "Swinv2Backbone":
reshaped_hidden_states = outputs.reshaped_hidden_states
self.assertEqual(len(reshaped_hidden_states), expected_num_layers)

View File

@@ -156,7 +156,7 @@ class UperNetModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase)
test_torchscript = False
has_attentions = False
test_torch_exportable = True
test_torch_exportable_strictly = not get_torch_major_and_minor_version() == "2.7"
test_torch_exportable_strictly = get_torch_major_and_minor_version() != "2.7"
def setUp(self):
self.model_tester = UperNetModelTester(self)

View File

@@ -144,7 +144,7 @@ class VitMatteModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase
test_resize_embeddings = False
test_head_masking = False
test_torch_exportable = True
test_torch_exportable_strictly = not get_torch_major_and_minor_version() == "2.7"
test_torch_exportable_strictly = get_torch_major_and_minor_version() != "2.7"
def setUp(self):
self.model_tester = VitMatteModelTester(self)

View File

@@ -155,7 +155,7 @@ class VitPoseModelTest(ModelTesterMixin, unittest.TestCase):
test_resize_embeddings = False
test_head_masking = False
test_torch_exportable = True
test_torch_exportable_strictly = not get_torch_major_and_minor_version() == "2.7"
test_torch_exportable_strictly = get_torch_major_and_minor_version() != "2.7"
def setUp(self):
self.model_tester = VitPoseModelTester(self)

View File

@@ -148,7 +148,7 @@ class ZoeDepthModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase
test_resize_embeddings = False
test_head_masking = False
# `strict=True/False` are both failing with torch 2.7, see #38677
test_torch_exportable = not get_torch_major_and_minor_version() == "2.7"
test_torch_exportable = get_torch_major_and_minor_version() != "2.7"
def setUp(self):
self.model_tester = ZoeDepthModelTester(self)