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

本站现有博文336篇,共被浏览944792

本站已经建立2655天!

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