LLM InternLM-Chat-7B 학자 모델, Baichuan-13B-Chat Baichuan 모델은 사용하기 쉽습니다.

실행할 GPU를 지정하려면:

#方式一 (两行必须放在import  torch前面)
#import os
# os.environ['CUDA_VISIBLE_DEVICES'] = '5'

#方式二(第一种不生效用这种,我这边这种可以生效)
#import torch
#torch.cuda.set_device(5)

1. InternLM-Chat-7B 학자 모델

참조:
https://huggingface.co/internlm/internlm-chat-7b ##모델 다운로드
https://github.com/InternLM/InternLM ## 웹 데모 사용 코드 참조 다운로드

GPU 테스트 요구 사항: 15g 이상(대화 라운드 후 일반적으로 15g는 비디오 메모리가 충분하지 않음)
간소화된 데모 코드가 매우 잘 작성됨

 from transformers import AutoTokenizer, AutoModelForCausalLM
 tokenizer = AutoTokenizer.from_pretrained("internlm/internlm-chat-7b", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("internlm/internlm-chat-7b", trust_remote_code=True).cuda()
 model = model.eval()
response, history = model.chat(tokenizer, "你好", history=[])
>>> print(response)
你好!有什么我可以帮助你的吗?
response, history = model.chat(tokenizer, "请提供三个管理时间的建议。", history=history)
>>> print(response)

여기에 이미지 설명 삽입

여기에 이미지 설명 삽입

2. Baichuan-13B-Chat Baichuan 모델은 사용하기 쉽습니다.

참조:
https://huggingface.co/baichuan-inc/Baichuan-13B-Chat ##모델 다운로드
https://github.com/baichuan-inc/Baichuan-13B ## 웹 데모 사용 코드 참조 다운로드

GPU 테스트 요구 사항: 20g 이상(여기서 device_map="auto"는 기본 멀티 그래픽 카드임)

(Envy는 온라인 정량 스크린샷으로, 이전에 CPU에 로드해야 하며 리소스 요구 사항도 매우 높습니다. 공식이 정량화된 int8, int4를 제공한 다음 테스트할 때까지 기다려야 합니다.)
여기에 이미지 설명 삽입

코드에서 모델 로드는 사용 가능한 모든 그래픽 카드를 사용하는 device_map='auto'를 지정합니다. 사용할 장치를 지정해야 하는 경우 export CUDA_VISIBLE_DEVICES=0,1(그래픽 카드 0 및 1 사용)과 유사한 방법을 사용할 수 있습니다.

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers.generation.utils import GenerationConfig
tokenizer = AutoTokenizer.from_pretrained("baichuan-inc/Baichuan-13B-Chat", use_fast=False, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("baichuan-inc/Baichuan-13B-Chat", device_map="auto", torch_dtype=torch.float16, trust_remote_code=True)
model.generation_config = GenerationConfig.from_pretrained("baichuan-inc/Baichuan-13B-Chat")
messages = []
messages.append({"role": "user", "content": "Which moutain is the second highest one in the world?"})
response = model.chat(tokenizer, messages)
print(response)

여기에 이미지 설명 삽입
여기에 이미지 설명 삽입
여기에 이미지 설명 삽입

추천

출처blog.csdn.net/weixin_42357472/article/details/131696020