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

本站现有博文332篇,共被浏览885739

本站已经建立2590天!

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