LoRA: ΔW = BA
rsLoRA: ΔW = (B * α/√r) * A
1 # Python 3.11+ 권장
2 pip install vllm >= 0.13 .0 # vLLM 사용 시
3 # 또는
4 pip install transformers >= 4.50 .0 torch >= 2.6 .0
1 vllm serve tellang/yeji-4b-rslora-v8.1 \
2 --host 0.0 .0.0 \
3 --port 8001 \
4 --dtype auto \
5 --max-model-len 4096 \
6 --gpu-memory-utilization 0.9
1 import openai
2
3 client = openai . OpenAI (
4 base_url = "http://localhost:8001/v1" ,
5 api_key = "EMPTY" ,
6 )
7
8 completion = client . chat . completions . create (
9 model = "tellang/yeji-4b-rslora-v8.1" ,
10 messages = [
11 { "role" : "system" , "content" : "당신은 운세를 알려주는 AI입니다." } ,
12 { "role" : "user" , "content" : "오늘의 운세를 알려주세요." }
13 ] ,
14 temperature = 0.7 ,
15 max_tokens = 2048 ,
16 )
17
18 print ( completion . choices [ 0 ] . message . content )
1 from transformers import AutoModelForCausalLM , AutoTokenizer
2 import torch
3
4 model_id = "tellang/yeji-4b-rslora-v8.1"
5 tokenizer = AutoTokenizer . from_pretrained ( model_id )
6 model = AutoModelForCausalLM . from_pretrained (
7 model_id ,
8 torch_dtype = torch . bfloat16 ,
9 device_map = "auto" ,
10 )
11
12 messages = [
13 { "role" : "system" , "content" : "당신은 운세를 알려주는 AI입니다." } ,
14 { "role" : "user" , "content" : "오늘의 연애운을 알려주세요." }
15 ]
16
17 text = tokenizer . apply_chat_template (
18 messages ,
19 tokenize = False ,
20 add_generation_prompt = True ,
21 )
22
23 inputs = tokenizer ( [ text ] , return_tensors = "pt" ) . to ( model . device )
24 outputs = model . generate (
25 ** inputs ,
26 max_new_tokens = 2048 ,
27 temperature = 0.7 ,
28 do_sample = True ,
29 )
30
31 response = tokenizer . decode ( outputs [ 0 ] , skip_special_tokens = True )
32 print ( response )
1 system_prompt = """당신은 운세 전문가입니다.
2 사용자의 질문에 대해 JSON 형식으로 응답하세요.
3
4 출력 형식:
5 {
6 "overall_summary": "전체 요약",
7 "사주분석": {...},
8 "타로": {...},
9 "주역": {...},
10 "성좌": {...},
11 "keywords": ["키워드1", "키워드2"],
12 "lucky_items": ["행운아이템1"],
13 "caution": "주의사항"
14 }
15 """
16
17 user_prompt = """
18 사용자 정보:
19 - 이름: 홍길동
20 - 생년월일: 1990-01-15
21 - 성별: 남
22 - 태어난 시간: 14시
23
24 운세 유형: 종합운세
25 """
1 system_prompt = """당신은 서양 점성술 전문가입니다.
2 JSON 형식으로 응답하세요.
3
4 출력 형식:
5 {
6 "overall_summary": "전체 요약",
7 "사랑운": {"score": 85, "description": "..."},
8 "직업운": {"score": 70, "description": "..."},
9 "건강운": {"score": 90, "description": "..."},
10 "돈운": {"score": 75, "description": "..."},
11 "인간관계운": {"score": 80, "description": "..."},
12 "keywords": ["행운", "성장"],
13 "lucky_items": ["루비"],
14 "caution": "주의사항"
15 }
16 """
17
18 user_prompt = """
19 사용자 정보:
20 - 별자리: 물병자리
21 - 생년월일: 1990-01-15
22 - 라이프패스 넘버: 7
23
24 운세 카테고리: 사랑운
25 """
1 system_prompt = """당신은 친근한 운세 상담사입니다.
2 사용자와 자연스럽게 대화하며 운세를 알려주세요.
3 """
4
5 user_prompt = "오늘 중요한 면접이 있는데, 조언해줄 수 있어?"
1 # rsLoRA 설정
2 lora_r : 64
3 lora_alpha : 128
4 lora_dropout : 0.05
5 target_modules : [ "q_proj" , "k_proj" , "v_proj" , "o_proj" , "gate_proj" , "up_proj" , "down_proj" ]
6
7 # 학습 설정
8 learning_rate : 2e-4
9 batch_size : 2
10 gradient_accumulation_steps : 4
11 epochs : 5
12 max_seq_length : 4096
13 warmup_steps : 100
14 weight_decay : 0.01
15
16 # 최적화
17 optimizer : adamw_8bit
18 scheduler : cosine
19 bf16 : true
20 gradient_checkpointing : true
1 def apply_chat_template_manual ( messages : list [ dict ] ) - > str :
2 """Unsloth 버그 우회: 직접 ChatML 포맷 생성"""
3 formatted = ""
4 for msg in messages :
5 role = msg [ "role" ]
6 content = msg [ "content" ]
7 formatted += f"<|im_start|> { role } \n { content } <|im_end|>\n"
8 formatted += "<|im_start|>assistant\n"
9 return formatted
1 import json
2 import re
3
4 def extract_json ( text : str ) - > dict :
5 """응답에서 JSON 추출"""
6 # 코드 블록 제거
7 text = re . sub ( r"```json\s*" , "" , text )
8 text = re . sub ( r"```\s*" , "" , text )
9
10 # JSON 파싱
11 return json . loads ( text . strip ( ) )
1 # GPU 메모리 사용률 낮추기
2 vllm serve tellang/yeji-4b-rslora-v8.1 \
3 --gpu-memory-utilization 0.7 \
4 --max-model-len 2048
1 @misc{yeji-4b-rslora-v8.1,
2 title={Yeji-4B-rsLoRA-v8.1: Korean Fortune-telling Language Model},
3 author={SSAFY YEJI Team},
4 year={2025},
5 publisher={HuggingFace},
6 url={https://huggingface.co/tellang/yeji-4b-rslora-v8.1}
7 }