[ci] pin ruff version and fix lint errors (#10681)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Yaowei Zheng
2026-07-24 16:29:58 +08:00
committed by GitHub
parent 3f77101580
commit 2ebe7be611
10 changed files with 30 additions and 21 deletions

View File

@@ -21,7 +21,7 @@ repos:
args: [--py39-plus] args: [--py39-plus]
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.13.2 rev: v0.15.5
hooks: hooks:
- id: ruff - id: ruff
args: [--fix] args: [--fix]

View File

@@ -2,9 +2,12 @@
check_dirs := scripts src tests tests_v1 check_dirs := scripts src tests tests_v1
ruff_version := 0.15.5
RUN := $(shell command -v uv >/dev/null 2>&1 && echo "uv run" || echo "") RUN := $(shell command -v uv >/dev/null 2>&1 && echo "uv run" || echo "")
BUILD := $(shell command -v uv >/dev/null 2>&1 && echo "uv build" || echo "python -m build") BUILD := $(shell command -v uv >/dev/null 2>&1 && echo "uv build" || echo "python -m build")
TOOL := $(shell command -v uv >/dev/null 2>&1 && echo "uvx" || echo "") TOOL := $(shell command -v uv >/dev/null 2>&1 && echo "uvx" || echo "")
RUFF := $(shell command -v uv >/dev/null 2>&1 && echo "uvx ruff@$(ruff_version)" || echo "ruff")
build: build:
$(BUILD) $(BUILD)
@@ -17,12 +20,12 @@ license:
$(RUN) python3 tests/check_license.py $(check_dirs) $(RUN) python3 tests/check_license.py $(check_dirs)
quality: quality:
$(TOOL) ruff check $(check_dirs) $(RUFF) check $(check_dirs)
$(TOOL) ruff format --check $(check_dirs) $(RUFF) format --check $(check_dirs)
style: style:
$(TOOL) ruff check $(check_dirs) --fix $(RUFF) check $(check_dirs) --fix
$(TOOL) ruff format $(check_dirs) $(RUFF) format $(check_dirs)
test: test:
WANDB_DISABLED=true $(RUN) pytest -vv --import-mode=importlib tests/ tests_v1/ WANDB_DISABLED=true $(RUN) pytest -vv --import-mode=importlib tests/ tests_v1/

View File

@@ -112,7 +112,7 @@ ignore = [
"D105", # no doc magic method "D105", # no doc magic method
"D107", # no doc __init__ "D107", # no doc __init__
] ]
extend-select = [ select = [
"C", # complexity "C", # complexity
"E", # error "E", # error
"F", # pyflakes "F", # pyflakes

View File

@@ -198,12 +198,16 @@ def _setup_lora_tuning(
pass # already loaded via load_unsloth_peft_model in loader.py pass # already loaded via load_unsloth_peft_model in loader.py
else: else:
if model_args.use_unsloth: if model_args.use_unsloth:
peft_model = load_unsloth_peft_model(config, model_args, finetuning_args, is_trainable=is_trainable) peft_model = load_unsloth_peft_model(
config, model_args, finetuning_args, is_trainable=is_trainable
)
if peft_model is not None: if peft_model is not None:
model = peft_model model = peft_model
if not model_args.use_unsloth: # unsloth was disabled or fell back if not model_args.use_unsloth: # unsloth was disabled or fell back
model = PeftModel.from_pretrained(model, adapter_to_resume, is_trainable=is_trainable, **init_kwargs) model = PeftModel.from_pretrained(
model, adapter_to_resume, is_trainable=is_trainable, **init_kwargs
)
logger.info_rank0("Loaded adapter(s): {}".format(",".join(model_args.adapter_name_or_path))) logger.info_rank0("Loaded adapter(s): {}".format(",".join(model_args.adapter_name_or_path)))

View File

@@ -120,9 +120,7 @@ def _noisy_mean_initialization(
avg_weight = _existing_embeddings(embed_weight, num_new_tokens, token_ids).mean(dim=0, keepdim=True) avg_weight = _existing_embeddings(embed_weight, num_new_tokens, token_ids).mean(dim=0, keepdim=True)
if token_ids: if token_ids:
noise_weight = torch.empty( noise_weight = torch.empty(len(token_ids), embedding_dim, device=embed_weight.device, dtype=embed_weight.dtype)
len(token_ids), embedding_dim, device=embed_weight.device, dtype=embed_weight.dtype
)
noise_weight.normal_(mean=0, std=(1.0 / math.sqrt(embedding_dim))) noise_weight.normal_(mean=0, std=(1.0 / math.sqrt(embedding_dim)))
embed_weight[token_ids] = avg_weight + noise_weight embed_weight[token_ids] = avg_weight + noise_weight
else: else:
@@ -202,8 +200,7 @@ def _description_based_initialization(
if len(valid_token_ids) == 0: if len(valid_token_ids) == 0:
# Fallback: use mean of all existing embeddings # Fallback: use mean of all existing embeddings
logger.warning_rank0( logger.warning_rank0(
f"Description for token '{token_str}' contains no valid tokens. " f"Description for token '{token_str}' contains no valid tokens. Using mean of existing embeddings."
"Using mean of existing embeddings."
) )
base_embedding = fallback_embedding base_embedding = fallback_embedding
else: else:

View File

@@ -278,7 +278,9 @@ class HyperParallelTrainer(CustomSeq2SeqTrainer):
) )
logical_batches = len(batch_sampler) // self._cp_size logical_batches = len(batch_sampler) // self._cp_size
dp_size = max(1, get_platform().get_world_size() // self._cp_size) dp_size = max(1, get_platform().get_world_size() // self._cp_size)
logical_length = logical_batches // dp_size if self.args.dataloader_drop_last else _ceil_div(logical_batches, dp_size) logical_length = (
logical_batches // dp_size if self.args.dataloader_drop_last else _ceil_div(logical_batches, dp_size)
)
dataloader_params = { dataloader_params = {
"batch_sampler": batch_sampler, "batch_sampler": batch_sampler,

View File

@@ -90,9 +90,7 @@ def _training_function(config: dict[str, Any]) -> None:
if finetuning_args.stage in ["pt", "sft"] and finetuning_args.use_hyper_parallel: if finetuning_args.stage in ["pt", "sft"] and finetuning_args.use_hyper_parallel:
if not is_hyper_parallel_available(): if not is_hyper_parallel_available():
raise ImportError( raise ImportError("hyper_parallel is not installed. Please install it with `pip install hyper_parallel`.")
"hyper_parallel is not installed. Please install it with `pip install hyper_parallel`."
)
if finetuning_args.stage == "pt": if finetuning_args.stage == "pt":
from .hyper_parallel import run_pt as run_pt_hp from .hyper_parallel import run_pt as run_pt_hp

View File

@@ -294,9 +294,7 @@ class BaseTrainer:
# mp_shard=world); a separate CP reduce would over-count by sqrt(cp_size). # mp_shard=world); a separate CP reduce would over-count by sqrt(cp_size).
total_norm = total_norm.full_tensor() total_norm = total_norm.full_tensor()
# pass a Tensor: clip_grads_with_norm_ clamps max_norm / (total_norm + 1e-6). # pass a Tensor: clip_grads_with_norm_ clamps max_norm / (total_norm + 1e-6).
torch.nn.utils.clip_grads_with_norm_( torch.nn.utils.clip_grads_with_norm_(self.model.parameters(), self.args.max_grad_norm, total_norm)
self.model.parameters(), self.args.max_grad_norm, total_norm
)
grad_norm = total_norm.item() grad_norm = total_norm.item()
if not torch.isfinite(torch.tensor(grad_norm)): # type: ignore # pyright: ignore [reportUnknownReturnType] if not torch.isfinite(torch.tensor(grad_norm)): # type: ignore # pyright: ignore [reportUnknownReturnType]

View File

@@ -19,6 +19,7 @@ from typing import TYPE_CHECKING
from ....utils import logging from ....utils import logging
from ....utils.plugin import BasePlugin from ....utils.plugin import BasePlugin
if TYPE_CHECKING: if TYPE_CHECKING:
from ....config.arg_utils import PluginConfig from ....config.arg_utils import PluginConfig
from ....utils.types import HFModel from ....utils.types import HFModel

View File

@@ -60,7 +60,13 @@ def create_eval_tab(engine: "Engine") -> dict[str, "Component"]:
input_elems.update({max_new_tokens, top_p, temperature, eval_seed, output_dir}) input_elems.update({max_new_tokens, top_p, temperature, eval_seed, output_dir})
elem_dict.update( elem_dict.update(
dict(max_new_tokens=max_new_tokens, top_p=top_p, temperature=temperature, eval_seed=eval_seed, output_dir=output_dir) dict(
max_new_tokens=max_new_tokens,
top_p=top_p,
temperature=temperature,
eval_seed=eval_seed,
output_dir=output_dir,
)
) )
with gr.Row(): with gr.Row():