1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_id = "gyung/lfm2-1.2b-koen-mt-v6.4-merged"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForCausalLM.from_pretrained(
7 model_id,
8 device_map="auto",
9 torch_dtype=torch.float16
10)
1messages = [
2 {"role": "system", "content": "Translate to Korean."},
3 {"role": "user", "content": "The training is progressing smoothly."}
4]
5
6input_ids = tokenizer.apply_chat_template(
7 messages,
8 return_tensors="pt",
9 add_generation_prompt=True
10).to(model.device)
11
12outputs = model.generate(
13 input_ids,
14 max_new_tokens=256,
15 do_sample=True,
16 temperature=0.3,
17 min_p=0.15,
18 repetition_penalty=1.05
19)
20
21decoded = tokenizer.decode(outputs[0][input_ids.shape[1]:], skip_special_tokens=True)
22print(decoded)
23# 출력: 학습이 순조롭게 진행되고 있습니다.
1messages = [
2 {"role": "system", "content": "Translate to English."},
3 {"role": "user", "content": "오늘 날씨가 정말 좋습니다."}
4]
5
6# 동일한 generate 코드 사용
7# 출력: The weather is really nice today.
1@misc{lfm2-koen-v6.4,
2 author = {gyung},
3 title = {LFM2-1.2B-KoEn-MT-v6.4: SFT-Enhanced Bidirectional Korean-English Translation Model},
4 year = {2024},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/gyung/lfm2-1.2b-koen-mt-v6.4-merged}
7}