EADST

Transformers Demo for DeepSeek-R1-Distill-Qwen-7B

Transformers Demo for DeepSeek-R1-Distill-Qwen-7B

from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = "/your_deepseek-ai_DeepSeek-R1-Distill-Qwen-7B_path"

model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)

prompt = "Give me a short introduction to large language model."
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=2048
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=False)[0] # show special tokens

print("Question: \n", text)
print("Answer: \n", response)
相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
Baidu Card 签证 Jupyter VGG-16 Translation OCR WAN Quantize Base64 Gemma Windows API Statistics Datetime CEIR Zip 图形思考法 GoogLeNet torchinfo Conda Pandas Vmess Michelin Excel CTC Crawler 算法题 git-lfs Website Google Pickle 递归学习法 云服务器 Password Ubuntu RAR ModelScope 顶会 阿里云 CC scipy SVR FastAPI Llama Hilton Data BeautifulSoup logger 多进程 NameSilo Anaconda NLTK Bin Quantization 净利润 v2ray OpenAI 腾讯云 飞书 财报 Django Dataset Ptyhon Bipartite IndexTTS2 mmap tqdm Miniforge Tiktoken DeepSeek FP32 Docker NLP RL 第一性原理 Streamlit Pillow Mixtral diffusers InvalidArgumentError Video ONNX XGBoost Heatmap BF16 CLAP Paper News XML Color Land HuggingFace Disk Diagram RGB Review Hungarian SPIE Github 图标 UI Paddle git Use PyCharm LaTeX Augmentation Markdown Clash LeetCode JSON Plate 报税 论文 ms-swift Hotel PDB Plotly 搞笑 icon hf OpenCV 继承 EXCEL Attention Food WebCrawler GPT4 Freesound YOLO Tensor Image2Text VPN COCO v0.dev 证件照 PIP TSV LLAMA Firewall PyTorch ChatGPT Bitcoin TensorFlow Transformers printf 公式 Rebuttal C++ Input FP64 Random CAM 关于博主 Animate Agent Breakpoint VSCode 音频 DeepStream TTS Pytorch CV QWEN CUDA 版权 Qwen uwsgi Tracking Sklearn Python Domain Magnet Algorithm SQLite llama.cpp Permission TensorRT Search GPTQ 多线程 UNIX CSV Knowledge Vim 域名 Claude 论文速读 PDF FlashAttention Web Proxy Qwen2.5 SAM Qwen2 Numpy 强化学习 Shortcut MD5 Math Interview GGML Distillation Cloudreve transformers ResNet-50 Git Logo Linux tar Safetensors AI SQL Bert Nginx Jetson uWSGI FP16 FP8 GIT LLM Template LoRA HaggingFace BTC
站点统计

本站现有博文333篇,共被浏览908554

本站已经建立2611天!

热门文章
文章归档
回到顶部