TechGPT2部署

1.环境

conda create -n techgpt python=3.10

conda activate techgpt

2.安装依赖

pip install transformers

pip install torch

pip install accelerate

3.克隆项目

开一下学术加速,然后克隆。

source /etc/network_turbo

git clone https://github.com/neukg/TechGPT-2.0.git

4.登录 Hugging Face 账户

pip install huggingface_hub

huggingface-cli login

5.下载模型到本地

python 复制代码
from huggingface_hub import snapshot_download

snapshot_download(
    repo_id="neukg/TechGPT-2.0-Qwen1.5-7b",
    local_dir="/root/autodl-tmp/TechGPT-2.0-Qwen1.5-7b",
    resume_download=True,
    local_dir_use_symlinks=False
)

6.运行

python 复制代码
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
import torch

# ✅ Qwen 的系统提示语(支持中英)
DEFAULT_SYSTEM_PROMPT = "You are a helpful assistant."

# ✅ Qwen 默认不使用 Alpaca 的 [INST] 模板,直接使用自然语言 prompt
example = "请把下列标题扩写成摘要, 不少于100字: 基于视觉语言多模态的实体关系联合抽取的研究。"

# ✅ 模型路径(改为你的 Qwen 模型保存目录)
ckpt_path = "/root/autodl-tmp/TechGPT-2.0-Qwen1.5-7b"

# ✅ 加载模型与 tokenizer(注意 trust_remote_code)
tokenizer = AutoTokenizer.from_pretrained(ckpt_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    ckpt_path,
    device_map="auto",                  # 自动选择 GPU
    torch_dtype=torch.float16,
    trust_remote_code=True
)
model.eval()

# ✅ Qwen 推荐使用的生成配置
generation_config = GenerationConfig(
    temperature=0.8,
    top_p=0.8,
    top_k=40,
    num_beams=1,
    do_sample=True,
    eos_token_id=tokenizer.eos_token_id,
    pad_token_id=tokenizer.pad_token_id,
    max_new_tokens=256,
)

# ✅ 构造输入
example = "请把下列标题扩写成摘要, 不少于100字: 基于视觉语言多模态的实体关系联合抽取的研究。"

prompt = f"<|im_start|>system\n{DEFAULT_SYSTEM_PROMPT}<|im_end|>\n<|im_start|>user\n{example}<|im_end|>\n<|im_start|>assistant\n"

inputs = tokenizer(prompt, return_tensors="pt").to(model.device)


# ✅ 生成回复
with torch.no_grad():
    generation_output = model.generate(
        **inputs,
        generation_config=generation_config,
        return_dict_in_generate=True,
        output_scores=True
    )
    output = generation_output.sequences[0]
    output_text = tokenizer.decode(output, skip_special_tokens=True)

# ✅ 打印结果
print("\n🧠 模型回复:")
print(output_text)

7.效果

相关推荐
金井PRATHAMA4 分钟前
主要分布在背侧海马体(dHPC)CA1区域(dCA1)的时空联合细胞对NLP中的深层语义分析的积极影响和启示
人工智能·神经网络·自然语言处理
说私域5 分钟前
技术赋能与营销创新:开源链动2+1模式AI智能名片S2B2C商城小程序的流量转化路径研究
人工智能·小程序·开源
YXWik61 小时前
Linux(centos7)安装 docker + ollama+ deepseek-r1:7b + Open WebUI(内含一键安装脚本)
linux·docker·ai
倒悬于世3 小时前
开源的语音合成大模型-Cosyvoice使用介绍
人工智能·python·语音识别
惜.己4 小时前
pytest中使用skip跳过某个函数
开发语言·python·测试工具·pytest
pk_xz1234564 小时前
光电二极管探测器电流信号处理与指令输出系统
人工智能·深度学习·数学建模·数据挖掘·信号处理·超分辨率重建
蓝蜂物联网4 小时前
边缘计算网关赋能智慧农业:物联网边缘计算的创新应用与实践
人工智能·物联网·边缘计算
酌沧4 小时前
AI图像编辑能力评测的8大测评集
人工智能
挽风8215 小时前
Excel file format cannot be determined, you must specify an engine manually.
python
tanak5 小时前
2025年7月23日 AI 今日头条
人工智能·microsoft