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

本站现有博文311篇,共被浏览742116

本站已经建立2381天!

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