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

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

本站已经建立2628天!

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