From 245028b9fae15fc4d154356d8db2fbee332ec7d8 Mon Sep 17 00:00:00 2001 From: XHPlus Date: Sat, 28 Mar 2026 16:34:05 +0800 Subject: [PATCH] fix: add missing whitespace around arithmetic operators Fixed PEP 8 compliance issues by adding proper spacing around arithmetic operators in f-strings and expressions. This resolves all flake8 E225/E226 formatting errors that were preventing pre-commit checks from passing. Co-Authored-By: Claude Opus 4.6 --- llmc/compression/quantization/quarot.py | 4 ++-- llmc/compression/quantization/spqr.py | 4 ++-- llmc/compression/quantization/tesseraq.py | 8 ++++---- .../sparsification/base_blockwise_sparsification.py | 4 ++-- llmc/compression/sparsification/dense.py | 4 ++-- llmc/compression/sparsification/shortgpt.py | 2 +- llmc/eval/eval_vqa.py | 4 ++-- llmc/models/mixtral.py | 5 +++-- 8 files changed, 18 insertions(+), 17 deletions(-) diff --git a/llmc/compression/quantization/quarot.py b/llmc/compression/quantization/quarot.py index 91bd855ae..55c56e318 100755 --- a/llmc/compression/quantization/quarot.py +++ b/llmc/compression/quantization/quarot.py @@ -96,7 +96,7 @@ def get_orthogonal_matrix(self): raise ValueError(f'Unsupported mode {self.mode}') def block_transform(self, block): - logger.info(f'Start transform the {self.block_idx+1}-th block') + logger.info(f'Start transform the {self.block_idx + 1}-th block') if self.online_rotate: self.replace_rotate_linears(block) @@ -108,7 +108,7 @@ def block_transform(self, block): gc.collect() logger.info(f'block:{block}') - logger.info(f'End transform the {self.block_idx+1}-th block') + logger.info(f'End transform the {self.block_idx + 1}-th block') @torch.no_grad() def subset_transform(self, block, subset): diff --git a/llmc/compression/quantization/spqr.py b/llmc/compression/quantization/spqr.py index a371b9356..8d5d58cc7 100755 --- a/llmc/compression/quantization/spqr.py +++ b/llmc/compression/quantization/spqr.py @@ -90,7 +90,7 @@ def block_transform_true_sequential(self, block, input_feat): @torch.no_grad() def block_transform(self, block, input_feat, *block_kwargs): - logger.info(f'Start transform the {self.block_idx+1}-th block') + logger.info(f'Start transform the {self.block_idx + 1}-th block') if self.true_sequential: self.block_transform_true_sequential(block, input_feat) @@ -103,7 +103,7 @@ def block_transform(self, block, input_feat, *block_kwargs): self.get_replacement_params(mode='fake_quant', w_only=True), ) - logger.info(f'End transform the {self.block_idx+1}-th block') + logger.info(f'End transform the {self.block_idx + 1}-th block') @torch.no_grad() def subset_transform(self, layers_dict): diff --git a/llmc/compression/quantization/tesseraq.py b/llmc/compression/quantization/tesseraq.py index 8c87f77ac..76925ae98 100644 --- a/llmc/compression/quantization/tesseraq.py +++ b/llmc/compression/quantization/tesseraq.py @@ -176,7 +176,7 @@ def collect_block_qparams(self, block, input_feat): @torch.no_grad() def block_transform(self, block, input_feat, block_kwargs): - logger.info(f'Start transform the {self.block_idx+1}-th block') + logger.info(f'Start transform the {self.block_idx + 1}-th block') with torch.no_grad(): block.float() @@ -204,7 +204,7 @@ def block_transform(self, block, input_feat, block_kwargs): if self.reduce_memory: block.to(self.model_dtype) - logger.info(f'End transform the {self.block_idx+1}-th block') + logger.info(f'End transform the {self.block_idx + 1}-th block') def tesseraq_train(self, block): self.set_dynamic_tmp_quant(block, on=True) @@ -273,8 +273,8 @@ def tesseraq_train(self, block): norm = loss_scaler(loss, optimizer, parameters=params_r + params_s) logger.info( - f'block {self.block_idx} iter {i+1} loss:{loss.item():5f} \ - norm:{norm.item():4f} HR progress:{(1-thresholds[i])*100:1f}% ' + f'block {self.block_idx} iter {i + 1} loss:{loss.item():5f} \ + norm:{norm.item():4f} HR progress:{(1 - thresholds[i]) * 100:1f}% ' ) for p in params_r + params_s: p.requires_grad = False diff --git a/llmc/compression/sparsification/base_blockwise_sparsification.py b/llmc/compression/sparsification/base_blockwise_sparsification.py index 42d73dfa2..1e0cc6d4d 100644 --- a/llmc/compression/sparsification/base_blockwise_sparsification.py +++ b/llmc/compression/sparsification/base_blockwise_sparsification.py @@ -154,7 +154,7 @@ def block_opt(self, block): self.block_transform(block) def block_transform(self, block, input_feat, block_kwargs): - logger.info(f'Start transform the {self.block_idx+1}-th block') + logger.info(f'Start transform the {self.block_idx + 1}-th block') subsets = self.model.get_subsets_in_block(block) for index, subset in enumerate(subsets): if not self.filter_subset(subset): @@ -174,7 +174,7 @@ def block_transform(self, block, input_feat, block_kwargs): inspect_module, subset_kwargs ) - logger.info(f'End transform the {self.block_idx+1}-th block') + logger.info(f'End transform the {self.block_idx + 1}-th block') def filter_subset(self, subset): return True diff --git a/llmc/compression/sparsification/dense.py b/llmc/compression/sparsification/dense.py index dad9612b8..5623f1f7d 100644 --- a/llmc/compression/sparsification/dense.py +++ b/llmc/compression/sparsification/dense.py @@ -11,6 +11,6 @@ def __init__(self, model, sparsity_config, input, padding_mask, config): super().__init__(model, sparsity_config, input, padding_mask, config) def block_transform(self, block): - logger.info(f'Start transform the {self.block_idx+1}-th block') + logger.info(f'Start transform the {self.block_idx + 1}-th block') logger.info(block) - logger.info(f'End transform the {self.block_idx+1}-th block') + logger.info(f'End transform the {self.block_idx + 1}-th block') diff --git a/llmc/compression/sparsification/shortgpt.py b/llmc/compression/sparsification/shortgpt.py index 9684e19d4..2e6dfc197 100644 --- a/llmc/compression/sparsification/shortgpt.py +++ b/llmc/compression/sparsification/shortgpt.py @@ -30,7 +30,7 @@ def block_opt(self, block): self.input['data'] = output_feat def block_transform(self, input_feat, output_feat): - logger.info(f'Start transform the {self.block_idx+1}-th block') + logger.info(f'Start transform the {self.block_idx + 1}-th block') self.subset_transform( input_feat, output_feat diff --git a/llmc/eval/eval_vqa.py b/llmc/eval/eval_vqa.py index b8fd65033..dd573454c 100755 --- a/llmc/eval/eval_vqa.py +++ b/llmc/eval/eval_vqa.py @@ -255,8 +255,8 @@ def _adjust_config(task_dict): gen_max_mem = torch.cuda.max_memory_allocated() / 1024 / 1024 logger.info(f'peak memory: {gen_max_mem:.1f} MB.') - logger.info(f'prefill average time: {prefill *1000:.1f} ms.') - logger.info(f'decode average time: {decode *1000:.1f} ms.') + logger.info(f'prefill average time: {prefill * 1000:.1f} ms.') + logger.info(f'decode average time: {decode * 1000:.1f} ms.') if hasattr(lm, '_model'): del lm._model diff --git a/llmc/models/mixtral.py b/llmc/models/mixtral.py index 0ca406710..aa0d54875 100644 --- a/llmc/models/mixtral.py +++ b/llmc/models/mixtral.py @@ -59,7 +59,8 @@ def get_subsets_in_block(self, block): return self._get_subsets_fused(block) def _get_subsets_legacy(self, block): - """transformers <5.0: block.block_sparse_moe with ModuleList experts.""" + """Transformers <5.0: block.block_sparse_moe with ModuleList + experts.""" moe = block.block_sparse_moe return [ { @@ -106,7 +107,7 @@ def _get_subsets_legacy(self, block): ] def _get_subsets_fused(self, block): - """transformers >=5.0: block.mlp with fused MixtralExperts.""" + """Transformers >=5.0: block.mlp with fused MixtralExperts.""" moe = block.mlp return [ {