Overview
The Qwen model loading API provides methods to load pre-trained models and tokenizers from Hugging Face or local paths. All models use the standard Transformers library interfaces.Load Model
Load a Qwen model for causal language modeling:Parameters
str
required
Model checkpoint name (e.g., “Qwen/Qwen-7B-Chat”) or local path to model directory
str | dict
default:"None"
Device allocation strategy:
"auto": Automatically distribute model across available devices"cpu": Load model to CPU only"cuda": Load model to GPU- Dictionary mapping layers to specific devices
bool
default:"False"
Allow execution of custom modeling code from the model repository. Required for Qwen models.
bool
default:"False"
Resume incomplete downloads from Hugging Face Hub
torch.dtype
default:"None"
Data type for model weights (e.g.,
torch.float16, torch.bfloat16)bool
default:"False"
Reduce CPU memory usage during model loading (useful for large models)
GPTQConfig | BitsAndBytesConfig
default:"None"
Configuration for model quantization (4-bit, 8-bit)
Returns
AutoModelForCausalLM
Loaded Qwen model ready for inference or fine-tuning
Load Tokenizer
Load the tokenizer associated with a Qwen model:Parameters
str
required
Model checkpoint name or path. Should match the model being loaded.
bool
default:"False"
Allow execution of custom tokenizer code. Required for Qwen models.
bool
default:"False"
Resume incomplete downloads from Hugging Face Hub
str
default:"right"
Side on which padding tokens are added:
"right": Pad on the right (recommended for training)"left": Pad on the left (recommended for generation)
bool
default:"True"
Use fast tokenizer implementation if available
int
default:"None"
Maximum sequence length for tokenization
Returns
AutoTokenizer
Loaded tokenizer with special tokens configured for Qwen
Load Generation Config
Load generation configuration from a checkpoint:Parameters
str
required
Model checkpoint name or path containing
generation_config.jsonbool
default:"False"
Allow execution of custom configuration code
bool
default:"False"
Resume incomplete downloads
Returns
GenerationConfig
Generation configuration with model-specific defaults