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

本站现有博文338篇,共被浏览989942次

本站已经建立2702天!

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