Skip to content

Commit 2ac95a9

Browse files
authored
Update formatting for latest Ruff version (#2041)
1 parent 6afe94f commit 2ac95a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+88
-87
lines changed

benchmarks/text_generation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def next(prompt, state, index):
150150
)
151151
print("Time taken: ", time_taken)
152152
res_handler.write(
153-
f"{sampler},{execution_method}," f"{time_taken}\n"
153+
f"{sampler},{execution_method},{time_taken}\n"
154154
)
155155
print()
156156
print("*************************************")

keras_hub/src/metrics/bleu.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,9 @@ def validate_and_fix_rank(inputs, tensor_name, base_rank=0):
329329
return tf.squeeze(inputs, axis=-1)
330330
else:
331331
raise ValueError(
332-
f"{tensor_name} must be of rank {base_rank}, {base_rank+1} "
333-
f"or {base_rank+2}. Found rank: {inputs.shape.rank}"
332+
f"{tensor_name} must be of rank {base_rank}, "
333+
f"{base_rank + 1}, or {base_rank + 2}. "
334+
f"Found rank: {inputs.shape.rank}"
334335
)
335336

336337
y_true = validate_and_fix_rank(y_true, "y_true", 1)

keras_hub/src/models/basnet/basnet_backbone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def get_resnet_block(_resnet, block_num):
219219
else:
220220
x = _resnet.pyramid_outputs[extractor_levels[block_num - 1]]
221221
y = _resnet.get_layer(
222-
f"stack{block_num}_block{num_blocks[block_num]-1}_add"
222+
f"stack{block_num}_block{num_blocks[block_num] - 1}_add"
223223
).output
224224
return keras.models.Model(
225225
inputs=x,

keras_hub/src/models/deeplab_v3/deeplab_v3_layers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ def build(self, input_shape):
8888
dilation_rate=dilation_rate,
8989
use_bias=False,
9090
data_format=self.data_format,
91-
name=f"aspp_conv_{i+2}",
91+
name=f"aspp_conv_{i + 2}",
9292
),
9393
keras.layers.BatchNormalization(
94-
axis=self.channel_axis, name=f"aspp_bn_{i+2}"
94+
axis=self.channel_axis, name=f"aspp_bn_{i + 2}"
9595
),
9696
keras.layers.Activation(
97-
self.activation, name=f"aspp_activation_{i+2}"
97+
self.activation, name=f"aspp_activation_{i + 2}"
9898
),
9999
]
100100
)

keras_hub/src/models/densenet/densenet_backbone.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ def __init__(
8181
channel_axis,
8282
stackwise_num_repeats[stack_index],
8383
growth_rate,
84-
name=f"stack{stack_index+1}",
84+
name=f"stack{stack_index + 1}",
8585
)
8686
pyramid_outputs[f"P{index}"] = x
8787
x = apply_transition_block(
8888
x,
8989
channel_axis,
9090
compression_ratio,
91-
name=f"transition{stack_index+1}",
91+
name=f"transition{stack_index + 1}",
9292
)
9393

9494
x = apply_dense_block(
@@ -140,7 +140,7 @@ def apply_dense_block(x, channel_axis, num_repeats, growth_rate, name=None):
140140

141141
for i in range(num_repeats):
142142
x = apply_conv_block(
143-
x, channel_axis, growth_rate, name=f"{name}_block{i+1}"
143+
x, channel_axis, growth_rate, name=f"{name}_block{i + 1}"
144144
)
145145
return x
146146

keras_hub/src/models/flux/flux_text_to_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(
8181

8282
def fit(self, *args, **kwargs):
8383
raise NotImplementedError(
84-
"Currently, `fit` is not supported for " "`FluxTextToImage`."
84+
"Currently, `fit` is not supported for `FluxTextToImage`."
8585
)
8686

8787
def generate_step(

keras_hub/src/models/pali_gemma/pali_gemma_presets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"pali_gemma_3b_mix_224": {
66
"metadata": {
77
"description": (
8-
"image size 224, mix fine tuned, text sequence " "length is 256"
8+
"image size 224, mix fine tuned, text sequence length is 256"
99
),
1010
"params": 2923335408,
1111
"path": "pali_gemma",
@@ -45,7 +45,7 @@
4545
"pali_gemma_3b_896": {
4646
"metadata": {
4747
"description": (
48-
"image size 896, pre trained, text sequence length " "is 512"
48+
"image size 896, pre trained, text sequence length is 512"
4949
),
5050
"params": 2927759088,
5151
"path": "pali_gemma",

keras_hub/src/models/resnet/resnet_backbone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def __init__(
177177
use_bias=False,
178178
padding="same",
179179
dtype=dtype,
180-
name=f"conv{conv_index+1}_conv",
180+
name=f"conv{conv_index + 1}_conv",
181181
)(x)
182182

183183
if not use_pre_activation:

keras_hub/src/models/retinanet/feature_pyramid.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ def build(self, input_shapes):
209209
)
210210
if i == backbone_max_level + 1 and self.use_p5:
211211
self.output_conv_layers[level].build(
212-
(None, None, None, input_shapes[f"P{i-1}"][-1])
212+
(None, None, None, input_shapes[f"P{i - 1}"][-1])
213213
if self.data_format == "channels_last"
214-
else (None, input_shapes[f"P{i-1}"][1], None, None)
214+
else (None, input_shapes[f"P{i - 1}"][1], None, None)
215215
)
216216
else:
217217
self.output_conv_layers[level].build(
@@ -277,7 +277,7 @@ def call(self, inputs):
277277
if i < backbone_max_level:
278278
# for the top most output, it doesn't need to merge with any
279279
# upper stream outputs
280-
upstream_output = self.top_down_op(output_features[f"P{i+1}"])
280+
upstream_output = self.top_down_op(output_features[f"P{i + 1}"])
281281
output = self.merge_op([output, upstream_output])
282282
output_features[level] = (
283283
self.lateral_batch_norm_layers[level](output)
@@ -296,9 +296,9 @@ def call(self, inputs):
296296
for i in range(backbone_max_level + 1, self.max_level + 1):
297297
level = f"P{i}"
298298
feats_in = (
299-
inputs[f"P{i-1}"]
299+
inputs[f"P{i - 1}"]
300300
if i == backbone_max_level + 1 and self.use_p5
301-
else output_features[f"P{i-1}"]
301+
else output_features[f"P{i - 1}"]
302302
)
303303
if i > backbone_max_level + 1:
304304
feats_in = self.activation(feats_in)

keras_hub/src/models/stable_diffusion_3/stable_diffusion_3_inpaint.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ def __init__(
8282

8383
def fit(self, *args, **kwargs):
8484
raise NotImplementedError(
85-
"Currently, `fit` is not supported for "
86-
"`StableDiffusion3Inpaint`."
85+
"Currently, `fit` is not supported for `StableDiffusion3Inpaint`."
8786
)
8887

8988
def generate_step(

keras_hub/src/models/vit/vit_layers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def build(self, input_shape):
351351
attention_dropout=self.attention_dropout,
352352
layer_norm_epsilon=self.layer_norm_epsilon,
353353
dtype=self.dtype_policy,
354-
name=f"tranformer_block_{i+1}",
354+
name=f"tranformer_block_{i + 1}",
355355
)
356356
encoder_block.build((None, None, self.hidden_dim))
357357
self.encoder_layers.append(encoder_block)

keras_hub/src/tokenizers/byte_tokenizer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ def __init__(
150150
):
151151
if not is_int_dtype(dtype):
152152
raise ValueError(
153-
"Output dtype must be an integer type. "
154-
f"Received: dtype={dtype}"
153+
f"Output dtype must be an integer type. Received: dtype={dtype}"
155154
)
156155

157156
# Check normalization_form.

keras_hub/src/tokenizers/unicode_codepoint_tokenizer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ def __init__(
203203
) -> None:
204204
if not is_int_dtype(dtype):
205205
raise ValueError(
206-
"Output dtype must be an integer type. "
207-
f"Received: dtype={dtype}"
206+
f"Output dtype must be an integer type. Received: dtype={dtype}"
208207
)
209208

210209
# Check normalization_form.

keras_hub/src/utils/timm/convert_densenet.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,20 @@ def port_batch_normalization(keras_layer_name, hf_weight_prefix):
5959
num_stacks = len(backbone.stackwise_num_repeats)
6060
for stack_index in range(num_stacks):
6161
for block_idx in range(backbone.stackwise_num_repeats[stack_index]):
62-
keras_name = f"stack{stack_index+1}_block{block_idx+1}"
62+
keras_name = f"stack{stack_index + 1}_block{block_idx + 1}"
6363
hf_name = (
64-
f"features.denseblock{stack_index+1}.denselayer{block_idx+1}"
64+
"features."
65+
f"denseblock{stack_index + 1}"
66+
f".denselayer{block_idx + 1}"
6567
)
6668
port_batch_normalization(f"{keras_name}_1_bn", f"{hf_name}.norm1")
6769
port_conv2d(f"{keras_name}_1_conv", f"{hf_name}.conv1")
6870
port_batch_normalization(f"{keras_name}_2_bn", f"{hf_name}.norm2")
6971
port_conv2d(f"{keras_name}_2_conv", f"{hf_name}.conv2")
7072

7173
for stack_index in range(num_stacks - 1):
72-
keras_transition_name = f"transition{stack_index+1}"
73-
hf_transition_name = f"features.transition{stack_index+1}"
74+
keras_transition_name = f"transition{stack_index + 1}"
75+
hf_transition_name = f"features.transition{stack_index + 1}"
7476
port_batch_normalization(
7577
f"{keras_transition_name}_bn", f"{hf_transition_name}.norm"
7678
)

keras_hub/src/utils/timm/convert_efficientnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def port_batch_normalization(keras_layer, hf_weight_prefix):
268268
# 97 is the start of the lowercase alphabet.
269269
letter_identifier = chr(block_idx + 97)
270270

271-
keras_block_prefix = f"block{stack_index+1}{letter_identifier}_"
271+
keras_block_prefix = f"block{stack_index + 1}{letter_identifier}_"
272272
hf_block_prefix = f"blocks.{stack_index}.{block_idx}."
273273

274274
if block_type == "v1":

keras_hub/src/utils/timm/convert_resnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def port_batch_normalization(keras_layer_name, hf_weight_prefix):
8989
for block_idx in range(backbone.stackwise_num_blocks[stack_index]):
9090
if version == "v1":
9191
keras_name = f"stack{stack_index}_block{block_idx}"
92-
hf_name = f"layer{stack_index+1}.{block_idx}"
92+
hf_name = f"layer{stack_index + 1}.{block_idx}"
9393
else:
9494
keras_name = f"stack{stack_index}_block{block_idx}"
9595
hf_name = f"stages.{stack_index}.blocks.{block_idx}"

tools/checkpoint_conversion/convert_albert_checkpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
FLAGS = flags.FLAGS
2222
flags.DEFINE_string(
23-
"preset", None, f'Must be one of {",".join(PRESET_MAP.keys())}'
23+
"preset", None, f"Must be one of {','.join(PRESET_MAP.keys())}"
2424
)
2525

2626

tools/checkpoint_conversion/convert_bart_checkpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
FLAGS = flags.FLAGS
2020
flags.DEFINE_string(
21-
"preset", None, f'Must be one of {",".join(PRESET_MAP.keys())}'
21+
"preset", None, f"Must be one of {','.join(PRESET_MAP.keys())}"
2222
)
2323

2424

tools/checkpoint_conversion/convert_bloom_checkpoints.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747

4848
flags.DEFINE_string(
49-
"preset", None, f'Must be one of {", ".join(PRESET_MAP.keys())}'
49+
"preset", None, f"Must be one of {', '.join(PRESET_MAP.keys())}"
5050
)
5151
flags.mark_flag_as_required("preset")
5252
flags.DEFINE_boolean(
@@ -244,9 +244,10 @@ def preprocessor_call(input_str):
244244

245245
def main(_):
246246
preset = FLAGS.preset
247-
assert (
248-
preset in PRESET_MAP.keys()
249-
), f'Invalid preset {preset}. Must be one of {", ".join(PRESET_MAP.keys())}'
247+
assert preset in PRESET_MAP.keys(), (
248+
f"Invalid preset {preset}. "
249+
f"Must be one of {', '.join(PRESET_MAP.keys())}"
250+
)
250251

251252
validate_only = FLAGS.validate_only
252253

tools/checkpoint_conversion/convert_clip_checkpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
flags.DEFINE_string(
6666
"preset",
6767
None,
68-
f'Must be one of {",".join(PRESET_MAP.keys())}',
68+
f"Must be one of {','.join(PRESET_MAP.keys())}",
6969
required=True,
7070
)
7171
flags.DEFINE_string(

tools/checkpoint_conversion/convert_deberta_v3_checkpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
FLAGS = flags.FLAGS
2929
flags.DEFINE_string(
30-
"preset", None, f'Must be one of {",".join(PRESET_MAP.keys())}'
30+
"preset", None, f"Must be one of {','.join(PRESET_MAP.keys())}"
3131
)
3232

3333

tools/checkpoint_conversion/convert_distilbert_checkpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
FLAGS = flags.FLAGS
2525
flags.DEFINE_string(
26-
"preset", None, f'Must be one of {",".join(PRESET_MAP.keys())}'
26+
"preset", None, f"Must be one of {','.join(PRESET_MAP.keys())}"
2727
)
2828

2929

tools/checkpoint_conversion/convert_electra_checkpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
flags.DEFINE_string(
3434
"preset",
3535
"electra_base_discriminator_en",
36-
f'Must be one of {",".join(PRESET_MAP)}',
36+
f"Must be one of {','.join(PRESET_MAP)}",
3737
)
3838
flags.mark_flag_as_required("preset")
3939

tools/checkpoint_conversion/convert_f_net_checkpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
FLAGS = flags.FLAGS
1919
flags.DEFINE_string(
20-
"preset", None, f'Must be one of {",".join(PRESET_MAP.keys())}'
20+
"preset", None, f"Must be one of {','.join(PRESET_MAP.keys())}"
2121
)
2222

2323

tools/checkpoint_conversion/convert_falcon_checkpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
absl.flags.DEFINE_string(
4444
"preset",
4545
"falcon_refinedweb_1b_en",
46-
f'Must be one of {",".join(PRESET_MAP.keys())}.',
46+
f"Must be one of {','.join(PRESET_MAP.keys())}.",
4747
)
4848

4949

tools/checkpoint_conversion/convert_gemma_checkpoints.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
flags.DEFINE_string(
5858
"preset",
5959
None,
60-
f'Must be one of {",".join(PRESET_MAP.keys())}',
60+
f"Must be one of {','.join(PRESET_MAP.keys())}",
6161
required=True,
6262
)
6363

@@ -228,9 +228,9 @@ def main(_):
228228
flax_dir = FLAGS.flax_dir
229229
else:
230230
presets = PRESET_MAP.keys()
231-
assert (
232-
preset in presets
233-
), f'Invalid preset {preset}. Must be one of {",".join(presets)}'
231+
assert preset in presets, (
232+
f"Invalid preset {preset}. Must be one of {','.join(presets)}"
233+
)
234234
handle = PRESET_MAP[preset]
235235
flax_dir = download_flax_model(handle)
236236

tools/checkpoint_conversion/convert_gpt2_checkpoints.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
FLAGS = flags.FLAGS
3030
flags.DEFINE_string(
31-
"preset", None, f'Must be one of {",".join(PRESET_MAP.keys())}'
31+
"preset", None, f"Must be one of {','.join(PRESET_MAP.keys())}"
3232
)
3333

3434

@@ -236,8 +236,8 @@ def check_output(
236236

237237
def main(_):
238238
assert FLAGS.preset in PRESET_MAP.keys(), (
239-
f'Invalid preset {FLAGS.preset}. '
240-
f'Must be one of {",".join(PRESET_MAP.keys())}'
239+
f"Invalid preset {FLAGS.preset}. "
240+
f"Must be one of {','.join(PRESET_MAP.keys())}"
241241
)
242242
num_params = PRESET_MAP[FLAGS.preset][0]
243243
hf_model_name = PRESET_MAP[FLAGS.preset][1]

tools/checkpoint_conversion/convert_llama3_checkpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
FLAGS = flags.FLAGS
2424
flags.DEFINE_string(
25-
"preset", None, f'Must be one of {",".join(PRESET_MAP.keys())}'
25+
"preset", None, f"Must be one of {','.join(PRESET_MAP.keys())}"
2626
)
2727

2828

tools/checkpoint_conversion/convert_llama_checkpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
FLAGS = flags.FLAGS
3535
flags.DEFINE_string(
36-
"preset", None, f'Must be one of {",".join(PRESET_MAP.keys())}'
36+
"preset", None, f"Must be one of {','.join(PRESET_MAP.keys())}"
3737
)
3838

3939
flags.DEFINE_string(

tools/checkpoint_conversion/convert_mistral_checkpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
FLAGS = flags.FLAGS
2727
flags.DEFINE_string(
28-
"preset", None, f'Must be one of {",".join(PRESET_MAP.keys())}'
28+
"preset", None, f"Must be one of {','.join(PRESET_MAP.keys())}"
2929
)
3030

3131

tools/checkpoint_conversion/convert_mix_transformer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
}
5353

5454
flags.DEFINE_string(
55-
"preset", None, f'Must be one of {",".join(DOWNLOAD_URLS.keys())}'
55+
"preset", None, f"Must be one of {','.join(DOWNLOAD_URLS.keys())}"
5656
)
5757

5858

0 commit comments

Comments
 (0)