Skip to content

Commit 2da0a10

Browse files
docs: add docstrings for the ModelScope download paths
The docstring coverage check flagged this diff at 25% against an 80% threshold. Document the download helpers, the model-directory loaders in LLM, and the ModelScope routing tests, which brings coverage of the functions touched by this PR to 93%. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: functionstackx <47992694+functionstackx@users.noreply.github.com>
1 parent c5c002e commit 2da0a10

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎tensorrt_llm/llmapi/llm.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,15 @@ def _build_model(self):
16681668
self._engine_dir, self._hf_model_dir = model_loader()
16691669

16701670
def _try_load_tokenizer(self) -> Optional[TokenizerBase]:
1671+
"""Resolve the tokenizer for this LLM instance.
1672+
1673+
Prefers an explicitly supplied tokenizer, then a single LoRA
1674+
directory on the PyTorch backends, and otherwise falls back to the
1675+
downloaded model directory or the configured model reference.
1676+
1677+
Returns:
1678+
The resolved tokenizer, or None when tokenizer init is skipped.
1679+
"""
16711680
if self.args.skip_tokenizer_init:
16721681
return None
16731682

@@ -1718,6 +1727,14 @@ def tokenizer(self, tokenizer: TokenizerBase):
17181727

17191728
def _try_load_generation_config(
17201729
self) -> Optional[transformers.GenerationConfig]:
1730+
"""Load the Hugging Face generation config for this model.
1731+
1732+
Reads from the downloaded model directory when one is available so
1733+
that remotely fetched snapshots are not re-resolved.
1734+
1735+
Returns:
1736+
The generation config, or None when the model does not ship one.
1737+
"""
17211738
model_dir = self._hf_model_dir or self.args.model
17221739
return ModelLoader.load_hf_generation_config(model_dir)
17231740

@@ -1729,6 +1746,14 @@ def _try_load_generation_config_explicit_values(self) -> dict[str, Any]:
17291746

17301747
def _try_load_hf_model_config(
17311748
self) -> Optional[transformers.PretrainedConfig]:
1749+
"""Load the Hugging Face model config for this model.
1750+
1751+
Reads from the downloaded model directory when one is available so
1752+
that remotely fetched snapshots are not re-resolved.
1753+
1754+
Returns:
1755+
The model config, or None when the model does not ship one.
1756+
"""
17321757
model_dir = self._hf_model_dir or self.args.model
17331758
return ModelLoader.load_hf_model_config(
17341759
model_dir, trust_remote_code=self.args.trust_remote_code)

‎tensorrt_llm/llmapi/utils.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ def __init__(self, *args, **kwargs):
232232

233233

234234
def download_hf_model(model: str, revision: Optional[str] = None) -> Path:
235+
"""Download a full model snapshot from the configured model hub.
236+
237+
Args:
238+
model: The model name or path.
239+
revision: The revision to use for the model.
240+
241+
Returns:
242+
The path to the downloaded model.
243+
"""
235244
ignore_patterns = ["original/**/*"]
236245
hub_name = "ModelScope" if use_modelscope() else "Hugging Face"
237246
logger.info(f"Downloading model {model} from {hub_name}")

‎tests/unittest/llmapi/test_utils.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222

2323

2424
def _stub_modelscope(monkeypatch, snapshot_download):
25+
"""Register a fake ``modelscope`` package exposing ``snapshot_download``.
26+
27+
Args:
28+
monkeypatch: The pytest monkeypatch fixture.
29+
snapshot_download: The callable to install as the hub entry point.
30+
"""
2531
modelscope = types.ModuleType("modelscope")
2632
hub = types.ModuleType("modelscope.hub")
2733
snapshot_module = types.ModuleType("modelscope.hub.snapshot_download")
@@ -33,9 +39,11 @@ def _stub_modelscope(monkeypatch, snapshot_download):
3339

3440

3541
def test_modelscope_download_maps_snapshot_filters(monkeypatch, tmp_path):
42+
"""Partial downloads forward allow patterns and revision to ModelScope."""
3643
calls = []
3744

3845
def snapshot_download(**kwargs):
46+
"""Record the hub call and return the temporary snapshot path."""
3947
calls.append(kwargs)
4048
return str(tmp_path)
4149

@@ -57,9 +65,11 @@ def snapshot_download(**kwargs):
5765

5866

5967
def test_modelscope_download_maps_ignored_files(monkeypatch, tmp_path):
68+
"""Full downloads forward the default ignore patterns to ModelScope."""
6069
calls = []
6170

6271
def snapshot_download(**kwargs):
72+
"""Record the hub call and return the temporary snapshot path."""
6373
calls.append(kwargs)
6474
return str(tmp_path)
6575

@@ -73,9 +83,11 @@ def snapshot_download(**kwargs):
7383

7484

7585
def test_hugging_face_download_remains_the_default(monkeypatch, tmp_path):
86+
"""Downloads route to Hugging Face when ModelScope is not enabled."""
7687
calls = []
7788

7889
def snapshot_download(model, **kwargs):
90+
"""Record the hub call and return the temporary snapshot path."""
7991
calls.append((model, kwargs))
8092
return str(tmp_path)
8193

@@ -90,6 +102,7 @@ def snapshot_download(model, **kwargs):
90102

91103

92104
def test_modelscope_download_requires_optional_dependency(monkeypatch):
105+
"""A missing ``modelscope`` install raises an actionable ImportError."""
93106
monkeypatch.setenv("TRTLLM_USE_MODELSCOPE", "true")
94107
monkeypatch.setitem(sys.modules, "modelscope", None)
95108
monkeypatch.delitem(sys.modules,

0 commit comments

Comments
 (0)