Apply several ruff SIM rules (#37283)
* Apply ruff SIM118 fix Signed-off-by: cyy <cyyever@outlook.com> * Apply ruff SIM910 fix Signed-off-by: cyy <cyyever@outlook.com> * Apply ruff SIM101 fix Signed-off-by: cyy <cyyever@outlook.com> * Format code Signed-off-by: cyy <cyyever@outlook.com> * More fixes Signed-off-by: cyy <cyyever@outlook.com> --------- Signed-off-by: cyy <cyyever@outlook.com>
This commit is contained in:
@@ -489,7 +489,7 @@ def _test_eager_matches_sdpa_inference(
|
||||
|
||||
def _config_zero_init(config):
|
||||
configs_no_init = copy.deepcopy(config)
|
||||
for key in configs_no_init.__dict__.keys():
|
||||
for key in configs_no_init.__dict__:
|
||||
if "_range" in key or "_std" in key or "initializer_factor" in key or "layer_scale" in key:
|
||||
setattr(configs_no_init, key, 1e-10)
|
||||
if isinstance(getattr(configs_no_init, key, None), PretrainedConfig):
|
||||
@@ -949,7 +949,7 @@ class ModelTesterMixin:
|
||||
state_dict = model.state_dict()
|
||||
|
||||
def check_equal(loaded):
|
||||
for key in state_dict.keys():
|
||||
for key in state_dict:
|
||||
max_diff = torch.max(
|
||||
state_dict()[key] ^ loaded[key]
|
||||
if isinstance(state_dict[key], torch.BoolTensor)
|
||||
@@ -1482,8 +1482,8 @@ class ModelTesterMixin:
|
||||
loaded_model_state_dict = loaded_model.state_dict()
|
||||
|
||||
non_persistent_buffers = {}
|
||||
for key in loaded_model_state_dict.keys():
|
||||
if key not in model_state_dict.keys():
|
||||
for key in loaded_model_state_dict:
|
||||
if key not in model_state_dict:
|
||||
non_persistent_buffers[key] = loaded_model_state_dict[key]
|
||||
|
||||
loaded_model_state_dict = {
|
||||
@@ -3431,7 +3431,7 @@ class ModelTesterMixin:
|
||||
set_seed(0)
|
||||
new_model = MyClass.from_pretrained(tmpdirname, num_labels=4, ignore_mismatched_sizes=True)
|
||||
|
||||
for key in new_model.state_dict().keys():
|
||||
for key in new_model.state_dict():
|
||||
# check weight values for weights with matched shapes are identical
|
||||
# (i.e. correctly loaded from the checkpoint)
|
||||
if key not in ["linear.weight", "linear.bias"]:
|
||||
@@ -3632,12 +3632,12 @@ class ModelTesterMixin:
|
||||
# set eager as it will be the one supported in all models
|
||||
# we just need to test if passing 'attn_implementation' as a dict fails or not
|
||||
attn_implementation_per_subconfig = {"": "eager"}
|
||||
for key in config.sub_configs.keys():
|
||||
for key in config.sub_configs:
|
||||
attn_implementation_per_subconfig[key] = "eager"
|
||||
|
||||
config._attn_implementation = attn_implementation_per_subconfig
|
||||
model = model_class(config)
|
||||
for key in config.sub_configs.keys():
|
||||
for key in config.sub_configs:
|
||||
sub_config = getattr(model.config, key)
|
||||
self.assertTrue(sub_config._attn_implementation == "eager")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user