Hugging Face · Transformers

Load a model and tokenizer

Load a language model, placing it on the best available device.

from transformers import AutoTokenizer, AutoModelForCausalLM

name = "Qwen/Qwen2.5-0.5B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(name)
model = AutoModelForCausalLM.from_pretrained(name, device_map="auto")

Official Hugging Face documentation

More transformers commands

All transformers commands · Hugging Face cheatsheet

Was this page helpful?