add comments to explain some ignores

This commit is contained in:
Ashwin Bharambe 2025-10-28 09:32:35 -07:00
parent 69fb43b7ee
commit d112e6347f
2 changed files with 8 additions and 0 deletions

View file

@ -358,6 +358,10 @@ class HFFinetuningSingleDevice:
if peft_config:
logger.info("Merging LoRA weights with base model")
# TRL's merge_and_unload returns a HuggingFace model
# Both cast() and type: ignore are needed here:
# - cast() tells mypy the return type is HFAutoModel for downstream code
# - type: ignore suppresses errors on the merge_and_unload() call itself,
# which mypy can't type-check due to TRL library's incomplete type stubs
model_obj = cast(HFAutoModel, trainer.model.merge_and_unload()) # type: ignore[union-attr,operator]
else:
# trainer.model is the trained HuggingFace model

View file

@ -599,6 +599,10 @@ def _combine_model_list_responses(endpoint: str, records: list[dict[str, Any]])
if endpoint == "/api/tags":
from ollama import ListResponse
# Both cast(Any, ...) and type: ignore are needed here:
# - cast(Any, ...) attempts to bypass type checking on the argument
# - type: ignore is still needed because mypy checks the call site independently
# and reports arg-type mismatch even after casting
body = ListResponse(models=cast(Any, ordered)) # type: ignore[arg-type]
return {"request": canonical_req, "response": {"body": body, "is_streaming": False}}