vllm_mlx.utils.tokenizer¶
Tokenizer utilities with fallback support for non-standard tokenizers.
View the complete module source at #L1-L280.
API details¶
Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.
vllm_mlx.utils.tokenizer
¶
Tokenizer utilities with fallback support for non-standard tokenizers.
Some models (e.g., Nemotron) use non-standard tokenizer configurations that transformers doesn't recognize. This module provides fallback loading directly from tokenizer.json.
vllm_mlx.utils.tokenizer.FALLBACK_MODELS
module-attribute
¶
vllm_mlx.utils.tokenizer._needs_tokenizer_fallback
¶
Check if model needs tokenizer fallback.
vllm_mlx.utils.tokenizer._needs_strict_false
¶
Check if model needs strict=False loading (VLM models with extra weights).
VLM models (e.g., Qwen3.5) have vision_tower weights that don't match the text-only model class. Loading with strict=True fails and wastes memory by loading all weights (~100 GB) before raising ValueError. Detect these models up-front to avoid the double-load penalty.
Source code in vllm_mlx/utils/tokenizer.py
vllm_mlx.utils.tokenizer.load_model_with_fallback
¶
Load model and tokenizer with fallback for non-standard tokenizers.
Parameters:
-
model_name(str) –HuggingFace model name or local path
-
tokenizer_config(dict, default:None) –Optional tokenizer configuration
Returns:
-
–
Tuple of (model, tokenizer)
Source code in vllm_mlx/utils/tokenizer.py
vllm_mlx.utils.tokenizer._load_strict_false
¶
Load model with strict=False to discard extra weights.
Handles models with extra parameters that the text-only model class doesn't define (e.g., vision tower weights in VLM models like Qwen3.5, or MTP layers). The model's own sanitize() handles key remapping (e.g., language_model.* prefix), and strict=False silently drops unmatched keys.
Source code in vllm_mlx/utils/tokenizer.py
vllm_mlx.utils.tokenizer._try_inject_mtp
¶
Inject MTP support if model has MTP config + weights.
Source code in vllm_mlx/utils/tokenizer.py
vllm_mlx.utils.tokenizer._try_inject_mtp_post_load
¶
Check if MTP weights exist but were stripped by sanitize(), and inject.
Source code in vllm_mlx/utils/tokenizer.py
vllm_mlx.utils.tokenizer._load_with_tokenizer_fallback
¶
Load model with fallback tokenizer for non-standard models like Nemotron.
Source code in vllm_mlx/utils/tokenizer.py
Complete contract reference¶
Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.
vllm_mlx.utils.tokenizer._needs_tokenizer_fallback · function
Check if model needs tokenizer fallback.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_name |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
any((pattern.lower() in model_lower for pattern in FALLBACK_MODELS))
Exceptions and behavior
Function _needs_tokenizer_fallback calls model_name.lower, any, pattern.lower; returns any((pattern.lower() in model_lower for pattern in FALLBACK_MODELS)).
No direct raise statement appears in this definition.
vllm_mlx.utils.tokenizer._needs_strict_false · function
Check if model needs strict=False loading (VLM models with extra weights).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_name |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
False;True
Exceptions and behavior
Function _needs_strict_false calls _download, load_config; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.utils.tokenizer.load_model_with_fallback · function
vllm_mlx.utils.tokenizer.load_model_with_fallback(model_name: str, tokenizer_config: dict = None) -> not annotated
Load model and tokenizer with fallback for non-standard tokenizers.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_name |
str |
yes |
none |
HuggingFace model name or local path |
tokenizer_config |
dict |
no |
None |
Optional tokenizer configuration |
Returns
- Type:
not annotated - Direct return expressions:
_load_with_tokenizer_fallback(model_name);_load_strict_false(model_name, tokenizer_config);(model, tokenizer)
Exceptions and behavior
Function load_model_with_fallback calls _needs_tokenizer_fallback, logger.info, _load_with_tokenizer_fallback, _needs_strict_false; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.utils.tokenizer._load_strict_false · function
vllm_mlx.utils.tokenizer._load_strict_false(model_name: str, tokenizer_config: dict = None) -> not annotated
Load model with strict=False to discard extra weights.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_name |
str |
yes |
none |
Required positional or keyword input. |
tokenizer_config |
dict |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Type:
not annotated - Direct return expressions:
(model, tokenizer)
Exceptions and behavior
Function _load_strict_false calls _download, load_model, tree_flatten, model.parameters; returns (model, tokenizer).
No direct raise statement appears in this definition.
vllm_mlx.utils.tokenizer._try_inject_mtp · function
Inject MTP support if model has MTP config + weights.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model |
not annotated |
yes |
none |
Required positional or keyword input. |
model_path |
not annotated |
yes |
none |
Required positional or keyword input. |
config |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
None
Exceptions and behavior
Function _try_inject_mtp calls config.get, text_config.get, inject_mtp_support; returns None.
No direct raise statement appears in this definition.
vllm_mlx.utils.tokenizer._try_inject_mtp_post_load · function
Check if MTP weights exist but were stripped by sanitize(), and inject.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model |
not annotated |
yes |
none |
Required positional or keyword input. |
model_name |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
None
Exceptions and behavior
Function _try_inject_mtp_post_load calls _download, Path, config_path.exists, open; returns None.
No direct raise statement appears in this definition.
vllm_mlx.utils.tokenizer._load_with_tokenizer_fallback · function
Load model with fallback tokenizer for non-standard models like Nemotron.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_name |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
(model, tokenizer)
Exceptions and behavior
Function _load_with_tokenizer_fallback calls logger.info, ensure_model_downloaded, load_model, tokenizer_json.exists; can raise ValueError; returns (model, tokenizer).
Directly raised exceptions: ValueError.
Complete symbol map¶
This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.
| Symbol | Kind | Signature and inputs | What it does | Source |
|---|---|---|---|---|
_needs_tokenizer_fallback |
function | _needs_tokenizer_fallback(model_name: str) -> bool |
Check if model needs tokenizer fallback. | #L25-L28 |
_needs_strict_false |
function | _needs_strict_false(model_name: str) -> bool |
Check if model needs strict=False loading (VLM models with extra weights). | #L31-L49 |
load_model_with_fallback |
function | load_model_with_fallback(model_name: str, tokenizer_config: dict = None) -> not annotated |
Load model and tokenizer with fallback for non-standard tokenizers. | #L52-L111 |
_load_strict_false |
function | _load_strict_false(model_name: str, tokenizer_config: dict = None) -> not annotated |
Load model with strict=False to discard extra weights. | #L114-L153 |
_try_inject_mtp |
function | _try_inject_mtp(model, model_path, config) -> not annotated |
Inject MTP support if model has MTP config + weights. | #L156-L176 |
_try_inject_mtp_post_load |
function | _try_inject_mtp_post_load(model, model_name) -> not annotated |
Check if MTP weights exist but were stripped by sanitize(), and inject. | #L179-L215 |
_load_with_tokenizer_fallback |
function | _load_with_tokenizer_fallback(model_name: str) -> not annotated |
Load model with fallback tokenizer for non-standard models like Nemotron. | #L218-L280 |