File size: 2,865 Bytes
8347832 8fad968 8347832 945d9c8 1faf122 945d9c8 1163aed 945d9c8 bfd119d 945d9c8 9101027 945d9c8 8347832 1163aed 1faf122 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
---
library_name: peft
base_model: beomi/open-llama-2-ko-7b
license: cc-by-sa-4.0
datasets:
- traintogpb/aihub-flores-koen-integrated-sparta-mini-300k
language:
- en
- ko
pipeline_tag: translation
---
### Pretrained LM
- [beomi/Llama-3-Open-Ko-8B](https://huggingface.co/beomi/Llama-3-Open-Ko-8B) (MIT License)
### Training Dataset
- [traintogpb/aihub-flores-koen-integrated-sparta-mini-300k](https://huggingface.co/datasets/traintogpb/aihub-flores-koen-integrated-sparta-mini-300k)
- Can translate in Enlgish-Korean (bi-directional)
### Prompt
- Template:
```python
prompt = f"Translate this from {src_lang} to {tgt_lang}\n### {src_lang}: {src_text}\n### {tgt_lang}: "
>>> # src_lang can be 'English', '한국어'
>>> # tgt_lang can be '한국어', 'English'
```
Mind that there is a "space (`_`)" at the end of the prompt (unpredictable first token will be popped up).
But if you use vLLM, it's okay to remove the final space(`_`).
### Training
- Trained with QLoRA
- PLM: NormalFloat 4-bit
- Adapter: BrainFloat 16-bit
- Adapted to all the linear layers (around 2.05%)
- Merge adapters and upscaled in BrainFloat 16-bit precision
### Usage (IMPORTANT)
- Should remove the EOS token at the end of the prompt.
```python
# MODEL
model_name = 'beomi/Llama-3-Open-Ko-8B'
adapter_name = 'traintogpb/llama-3-enko-translator-8b-qlora-adapter'
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type='nf4',
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_use_double_quant=True
)
model = AutoModelForCausalLM.from_pretrained(
model_name,
max_length=768,
quantization_config=bnb_config,
attn_implementation='flash_attention_2',
torch_dtype=torch.bfloat16,
)
model = PeftModel.from_pretrained(
model,
adapter_path=adapter_name,
torch_dtype=torch.bfloat16,
)
tokenizer = AutoTokenizer.from_pretrained(adapter_name)
tokenizer.pad_token_id = 128002 # eos_token_id and pad_token_id should be different
text = "Someday, QWER will be the greatest girl band in the world."
input_prompt = f"Translate this from English to 한국어.\n### English: {text}\n### 한국어:"
inputs = tokenizer(input_prompt, max_length=768, truncation=True, return_tensors='pt')
if inputs['input_ids'][0][-1] == tokenizer.eos_token_id:
inputs['input_ids'] = inputs['input_ids'][0][:-1].unsqueeze(dim=0)
inputs['attention_mask'] = inputs['attention_mask'][0][:-1].unsqueeze(dim=0)
outputs = model.generate(**inputs, max_length=768, eos_token_id=tokenizer.eos_token_id)
input_len = len(inputs['input_ids'].squeeze())
translation = tokenizer.decode(outputs[0][input_len:], skip_special_tokens=True)
print(translation)
```
### Framework versions
- PEFT 0.8.2
|