6.本地安装Fingpt

文章目录

1 依赖环境设置

本地环境

  • Python 3.10

  • CUbDA (可选)

  • PyTorch

云环境-魔塔

2.DeepSeek R1模型部署

DeepSeek R1

  • 1.5B
    •CPU: 4核心
    •内存: 8G
    •显卡:非必须
    •场景:聊天机器人,简单对话
  • 7B/8B
    •CPU: 6-8核心
    •内存: 16G
    •显卡:推荐8GB显存,例如RTX 3060/4060
    •场景:文本摘要,翻译,轻量级多轮对话
  • 14B
    •CPU: 12核心
    •内存: 64G
    •显卡:推荐16GB显存,例如RTX 3080/4080
    •场景:复杂任务,长文本理解与生成
  • 32B
    •CPU: 16核心
    •内存: 128G
    •显卡:推荐24GB显存,例如RTX 3090/4090, A100或V100
    •场景:高精度专业任务,医疗/金融/法律咨询
shell 复制代码
Linux环境执行如下命令(官方)
curl-fsSL https://ollama.com/install.sh|sh
魔塔环境
modelscope download--model=modelscope/ollama-linux--local _ dir./ollama
cd ollama-linux
sudo chmod+x./ollama-modelscopeinstall.sh
./ollama-modelscopeinstall.sh
ollama serve
环境参数
OLLAMA_MODELS=自定义路径
多GPU支持
CUDA_VISIBLE_DEVICES=0,1
通过ollama命令拉取模型
ollama run deepseek-r1:7b

3.FinGPT模型部署

安装FinGPT Python依赖包

shell 复制代码
pip install-Utransformers==4.40.1peft==0.5.0
pip install-U sentencepiece
pip install-U accelerate
pip install-U datasets
pip install-U bitsandbytes
如果模型在CPU上运行
pip3 install torch torchvision torchaudio
如果模型在GPU上运行
#确定CUDA版本nvcc- version
输出: Cuda compilation tools, release 12.1, V12.1.66
pip3 install torch torchvision torchaudio-index-url https://download. pytorch. org/ whl/ cu121

验证pytorch安装结果

python 复制代码
import torch
print(torch._version_)
print(torch.cuda.is_available())

运行FinGPT

python 复制代码
import torch
from transformers import  LlamaForCausalLM, LlamaTokenizerFast
from peft import PeftModel  # 0.5.0


base_model = "meta-llama/Meta-Llama-3-8B"
peft_model = "FinGPT/fingpt-mt_llama3-8b_lora"
prompt = [
    """Instruction: What is the sentiment of this news? Please choose an answer from {negative/neutral/positive}
    Input: FINANCING OF ASPOCOMP 'S GROWTH Aspocomp is aggressively pursuing its growth strategy by increasingly focusing on technologically more demanding HDI printed circuit boards PCBs.
    Answer:""",
    """Instruction: What is the sentiment of this news? Please choose an answer from {negative/neutral/positive}
    Input: According to Gran , the company has no plans to move all production to Russia , although that is where the company is growing.
    Answer:"""
]

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")



model = LlamaForCausalLM.from_pretrained(base_model, trust_remote_code=True, device_map="cuda", torch_dtype=torch.float16)
model = PeftModel.from_pretrained(model, peft_model)
model = model.eval()
model = model.to(device)

tokenizer = LlamaTokenizerFast.from_pretrained(base_model, trust_remote_code=True)
tokenizer.pad_token = tokenizer.eos_token
tokens = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True).to(device)

res =model.generate(**tokens, max_new_tokens=512)
res_sentences = [tokenizer.decode(i) for i in res]
out_text=[o.split("Answer:")[1] for o in res_sentences]


for sentiment in out_text:
    print(sentiment)

4.总结与思考

  1. 如何通过Ollama部署DeepSeek R1模型?
  2. FinGPT不同版本之间的差异是什么?
  3. FinGPT使用哪种技术调优基础模型?
  4. 如何设计Prompt指导FinGPT完成情感分析任务?
相关推荐
默_笙1 天前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的
python
qq_426003961 天前
启动playwright录制codegen生成自动化测试脚本
python·自动化
虎头金猫1 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
长沙三为智能科技1 天前
家政小程序开发从0到上线:五阶段交付流程与验收清单
python
1点东西1 天前
做了近两年的Agent开发,其实真正要学的就是这五件事
llm·agent·ai编程
伞伞悦读1 天前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
只睡四小时1 天前
Canvas 弹道联机实战:700 行 + 固定时间步长
python·websocket·html5·游戏开发·canvas
奇思妙想聪明勤奋的小羊1 天前
DeepAgents第5章:子Agent 与上下文隔离—让 Agent学会委派
人工智能·python·学习·语言模型
lpfasd1232 天前
2026年第38周GitHub趋势周报
python·科技·github
IZero072 天前
Jev 与 Laya
python·语言模型