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

本站现有博文330篇,共被浏览861146

本站已经建立2569天!

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