Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows端部署 #75

Open
Longleaves opened this issue Dec 28, 2023 · 3 comments
Open

windows端部署 #75

Longleaves opened this issue Dec 28, 2023 · 3 comments

Comments

@Longleaves
Copy link

请问能否部署在windows端呢?除了docker外,有没有直接详细的环境配置?

@lilianlhl
Copy link
Contributor

lilianlhl commented Dec 29, 2023

您好,可以在windows端部署2.1B 模型。需要配置5G以上内存,Python3.9+,及如下依赖,
transformers==4.36.2
torch==2.0.1
Flask==1.1.2
Flask-RESTful==0.3.9
accelerate==0.25.0
einops==0.7.0

将模型文件 [https://huggingface.co/IEITYuan/Yuan2-2B-hf/tree/main]下载到指定路径yuan-2B-path,并手工关掉Flash attention即可。(手工关掉Flash attention:1. 修改 config.json中"use_flash_attention"为 false;
2. 注释掉 yuan_hf_model.py中第35、36行;3. 修改yuan_hf_model.py中第271行为 inference_hidden_states_memory = torch.empty(bsz, 2, hidden_states.shape[2], dtype=hidden_states.dtype)。)

运行代码如下:
import sys, os
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(file), os.path.pardir)))
from transformers import AutoModelForCausalLM, LlamaTokenizer

print("Creat tokenizer...")
tokenizer = LlamaTokenizer.from_pretrained(yuan-2B-path)
tokenizer.add_tokens(['', '', '', '', '<FIM_SUFFIX>', '<FIM_PREFIX>', '<FIM_MIDDLE>','<commit_before>','<commit_msg>','<commit_after>','<jupyter_start>','<jupyter_text>','<jupyter_code>','<jupyter_output>','<empty_output>'], special_tokens=True)

print("Creat model...")
model = AutoModelForCausalLM.from_pretrained(yuan-2B-path, device_map="cpu", trust_remote_code=True).eval() #cpu 代码

inputs = tokenizer("请问目前最先进的机器学习算法有哪些?", return_tensors="pt")["input_ids"].to("cpu")
outputs = model.generate(inputs, do_sample=True, top_k=5, max_length=100)
print(tokenizer.decode(outputs[0]))

@Shawn-IEITSystems
Copy link
Collaborator

@Longleaves 可以通过YuanChat实现在windows上的快速部署,详见: https://github.com/IEIT-Yuan/YuanChat

@Huifu1018
Copy link
Contributor

请问能否部署在windows端呢?除了docker外,有没有直接详细的环境配置?

基于YuanChat快速搭建对话应用教程,详见:https://github.com/IEIT-Yuan/YuanChat/blob/main/docs/%E5%9C%A8%E7%AC%94%E8%AE%B0%E6%9C%AC%E4%B8%8A%E5%BF%AB%E9%80%9F%E9%83%A8%E7%BD%B2YuanModel%E5%92%8CYuanChat.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants