Downloads · 30 days
29
9% of all-time downloads
seong67360/Qwen2.5-7B-Instruct_v4
Qwen2.5-7B-Instruct_v4 is a text generation model from seong67360. Use it when you need the model to write or continue text. It is set up for transformers.
이 저장소는 Amazon SageMaker를 사용하여 Qwen 2.5 7B Instruct 모델을 파인튜닝하는 코드를 포함하고 있습니다. 이 프로젝트는 대규모 언어 모델의 효율적인 파인튜닝을 위해 QLoRA(Quantized Low-Rank Adaptation)를 사용합니다.
Downloads · 30 days
29
9% of all-time downloads
All-time downloads
327
Public
Parameters
7.6B
30.5 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors30.5 GB · 100%
From the Hugging Face model README
이 저장소는 Amazon SageMaker를 사용하여 Qwen 2.5 7B Instruct 모델을 파인튜닝하는 코드를 포함하고 있습니다. 이 프로젝트는 대규모 언어 모델의 효율적인 파인튜닝을 위해 QLoRA(Quantized Low-Rank Adaptation)를 사용합니다.
pip install torch transformers accelerate
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
# CUDA 사용 가능 여부 확인
if torch.cuda.is_available():
print(f"Using GPU: {torch.cuda.get_device_name(0)}")
else:
print("Warning: CUDA not available, using CPU")
# 모델과 토크나이저 로드
model = AutoModelForCausalLM.from_pretrained(
"seong67360/Qwen2.5-7B-Instruct_v4",
device_map="auto",
trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained(
"seong67360/Qwen2.5-7B-Instruct_v4",
trust_remote_code=True
)
# 대화 예시
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is quantum computing?"}
]
# 응답 생성
response = model.chat(tokenizer, messages)
print(response)
GPU 메모리가 제한된 경우, 8비트 또는 4비트 양자화를 사용할 수 있습니다:
# 8비트 양자화
model = AutoModelForCausalLM.from_pretrained(
"seong67360/Qwen2.5-7B-Instruct_v4",
device_map="auto",
trust_remote_code=True,
load_in_8bit=True
)
# 또는 4비트 양자화
model = AutoModelForCausalLM.from_pretrained(
"seong67360/Qwen2.5-7B-Instruct_v4",
device_map="auto",
trust_remote_code=True,
load_in_4bit=True
)
response = model.chat(
tokenizer,
messages,
temperature=0.7, # 높을수록 더 창의적인 응답
top_p=0.9, # 샘플링에 사용될 누적 확률의 임계값
max_new_tokens=512, # 생성할 최대 토큰 수
repetition_penalty=1.1 # 반복 방지를 위한 페널티 (1.0 이상)
)
.
├── scripts/
│ ├── train.py
│ ├── tokenization_qwen2.py
│ ├── requirements.txt
│ └── bootstrap.sh
├── sagemaker_train.py
└── README.md
프로젝트에서 사용하는 주요 의존성:
Qwen/Qwen2.5-7B-Instruct{
'epochs': 3,
'per_device_train_batch_size': 4,
'gradient_accumulation_steps': 8,
'learning_rate': 1e-5,
'max_steps': 1000,
'bf16': True,
'max_length': 2048,
'gradient_checkpointing': True,
'optim': 'adamw_torch',
'lr_scheduler_type': 'cosine',
'warmup_ratio': 0.1,
'weight_decay': 0.01,
'max_grad_norm': 0.3
}
학습 환경은 분산 학습 및 메모리 관리를 위한 최적화로 구성되어 있습니다:
환경 준비:
requirements.txt 생성bootstrap.sh 생성모델 로딩:
데이터셋 처리:
학습:
학습 과정에서 다음 메트릭을 추적합니다:
구현에는 포괄적인 오류 처리 및 로깅이 포함되어 있습니다:
python sagemaker_train.py
프로젝트는 다음 기능이 포함된 Qwen2 토크나이저의 커스텀 구현(tokenization_qwen2.py)을 포함합니다: