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

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

本站已经建立2631天!

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