T-Llama / README.md
1TuanPham's picture
Update README.md
d053eb5 verified
|
raw
history blame
No virus
9.62 kB
metadata
license: apache-2.0
language:
  - vi
  - en

Image

Model Details

  • Developed by: Tuan Pham (FPTU HCM Student)
  • Model type: Llama2-7B Decoder-only
  • Finetuned from model :
    • meta-llama/Llama-2-7b
    • bkai-foundation-models/vietnamese-llama2-7b-120GB
    • yeen214/llama2_7b_merge_orcafamily.
  • Bilingual support : English and Vietnamese

Model Description

This model is a proof of effort that one man can fine-tune his own model to reach SOTA.

Model Sources

Uses

Prompt template

[SYSTEM_PROMPT]

 ####### Instruction:
[INPUT]

 %%%%%%% Response:
[RESPONSE]

Recommend keeping the system prompt in english.

How to Get Started with the Model

Use the code below to get started with the model.

import torch
from torch.cuda.amp import autocast
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer, pipeline


def prompt_format(system_prompt, instruction):
    prompt = f"""{system_prompt}

 ####### Instruction:
{instruction}

 %%%%%%% Response:
"""
    return prompt

system_prompt = """
You're an AI Large Language Model developed(created) by an AI developer named Tuấn, the architecture of you is decoder-based LM, your task are to think loudly step by step before give a good and relevant response
to the user request, answer in the language the user preferred.

The AI has been trained to answer questions, provide recommendations, and help with decision making. The AI thinks outside the box and follows the user requests
"""
instruction = "Xin chào"

formatted_prompt = prompt_format(system_prompt, instruction)
print(formatted_prompt)

model_name = "1TuanPham/T-Llama"
model = AutoModelForCausalLM.from_pretrained(model_name,
                                             torch_dtype=torch.bfloat16,
                                             use_cache=True,
                                             device_map="auto"
                                             )
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
streamer = TextStreamer(tokenizer, skip_special_tokens=True)
pipe = pipeline("text-generation", model=base_model, tokenizer=tokenizer, streamer=streamer)

with autocast():
  output_default = pipe(formatted_prompt, pad_token_id=50256, max_new_tokens=128)

Example outputs:

> Xin chào

Xin chào! Tôi là một AI được phát triển bởi một AI nhà phát triển tên là Tuấn. Tôi được thiết kế để giúp đỡ người dùng bằng cách trả lời các câu hỏi, đưa ra đề xuất và hỗ trợ trong quá trình ra quyết định.
Tôi có thể hỗ trợ bạn bằng cách nghĩ ra các câu trả lời hay và phù hợp cho các câu hỏi của bạn.

> Việt Nam có cà phê gì nổi tiếng thế giới ?

Cà phê robusta của Việt Nam nổi tiếng trên toàn cầu. Loại cà phê này được trồng chủ yếu ở các vùng đất cao như Lâm Đồng, Gia Lai, KonTum và có hương vị đậm đà, đắng hơn so với cà phê Arabica.
Cà phê robusta thường được sử dụng để pha chế các loại cà phê espresso và phin truyền thống.

> Tôi có 500$ hãy build cho tôi một bộ PC

Để xây dựng một bộ PC với 500 USD, bạn có thể bắt đầu bằng cách chọn các thành phần chính như CPU, GPU, bộ nhớ và bộ lưu trữ. Sau đó, bạn có thể thêm các thành phần bổ sung như loa, bàn phím và chuột để hoàn thiện hệ thống.

Dưới đây là một số gợi ý về cách bạn có thể cấu thành một bộ PC với 500 USD:

1. CPU: Intel Core i5-12400 hoặc AMD Ryzen 5 5600X là những lựa chọn tốt để bắt đầu.

2. GPU: Nvidia GeForce GTX 1650 hoặc AMD Radeon RX 570 là những lựa chọn tốt để bắt đầu.

3. Bộ nhớ: 8GB RAM là một khởi đầu tốt.

4. Bộ lưu trữ: 500 GB ổ cứng SSD là một khởi đầu tốt.

5. Bàn phím và chuột: Bàn phím và chuột có thể được mua riêng hoặc cùng một bộ.

6. Loa: Một loa có thể được mua riêng hoặc cùng một bộ với bàn phím và chuột.

> Cho tôi 3 thức uống để giúp ngủ ngon hơn

Chắc chắn! Dưới đây là ba thức uống có thể giúp bạn ngủ ngon hơn:

1. Mật ong và chanh: Trộn một thìa mật ong với một thìa nước cốt chanh và uống trước khi đi ngủ. Mật ong có tác dụng làm dịu, trong khi chanh có chứa chất chống oxy hóa có thể giúp cải thiện chất lượng giấc ngủ.

2. Trà thảo dược: Một số loại trà thảo dược như hoa cúc, hoa oải hương và hoa sen có tác dụng thư giãn và giúp bạn chìm vào giấc ngủ. Hãy thử pha một ấm trà thảo dược ấm và uống trước khi đi ngủ.

3. Sữa ấm: Sữa ấm có chứa tryptophan, một loại hormone giúp bạn cảm thấy dễ chịu và thư giãn. Nó cũng có thể giúp thúc đẩy sản xuất melatonin, hormone giúp bạn chìm vào giấc ngủ. Hãy thử uống một cốc sữa ấm trước khi đi ngủ để giúp bạn ngủ ngon hơn.

The translated data has been thoroughly cleaned from the coding task, so in theory, the model should be able to code normally by incorporating the coding capabilities from the English coding examples task. (The translation will translate code definitions and variables.)

I would not recommend running any code generated from this model.

> Viết cho tôi một đoạn code bằng python xây dựng một ứng dụng bằng Flask hiển thị 'Xin chào thế giới' trên màn hình

Để viết một đoạn mã Python xây dựng một ứng dụng bằng Flask hiển thị 'Xin chào thế giới' trên màn hình, bạn có thể làm theo các bước sau:

1. Cài đặt Flask và các thư viện cần thiết:

  ```
  pip install flask
  ```

2. Tạo một ứng dụng Flask mới:

  ```
  app = Flask(__name__)
  ```

3. Thêm một route để hiển thị 'Xin chào thế giới':

  ```
  @app.route('/')
  def hello():
     return 'Xin chào thế giới!'
  ```

4. Khởi tạo ứng dụng Flask:

  ```
  app.run()
  ```

5. Chạy ứng dụng Flask:

  ```
  app.run(debug=True)
  ```

6. Mở trình duyệt và truy cập vào địa chỉ IP hoặc tên máy chủ của máy tính hoặc máy chủ nơi bạn đã khởi động ứng dụng Flask.

These examples are sub-optimal as they were generated with greedy decoding to ensure reproducibility. Here's the recommended configuration:

  • top_k=50
  • top_p=0.5
  • temperature=0.5
  • penalty_alpha=0.7
  • repetition_penalty=1.15

Note: 120GB of pre-trained Vietnamese  data might not be enough for a general question about Vietnamese events.

Here is a kaggle script to quickly test the model:

Training Details

Hardware Type:

  • GPU: VGA NVIDIA Tesla P100 16GB
  • SYSTEM RAM: 29GB

Hours used: ~47.5 days Approx*

Training Data

  • BactrianX
  • OpenOrca_translated
  • WizardLM_70k_translated
  • TigerLabMathInstruct_translated_vi
  • GradeSchoolMathInstruct_translated
  • vilm_lima-vi
  • MTEngVietnamese
  • databricks_dolly15k_translated
  • AlpacaCleaned_translated
  • databricks_dolly15k
  • OpenOrca
  • GradeSchoolMathInstruct
  • AlpacaCleaned
  • WebglmQA

Training Procedure

  • Learning rate: 2e-5 cosine

  • Optimizer: PagedLion8bit

  • QLora: rank: 64 /Q: 4-bit

  • Batch size: 2

  • Gradient accumulation: 128

  • Effective batch size: 256

    • 250k examples of 70% Vietnamese 30% English for 3.37 epoch
    • 350k examples of 60% Vietnamese 40% English for 1.4 epoch

Training loss

Last 10 runs:

image/png

Each line is 12 hours

All run plots:

image/png

A bad way to visualize i know...

Evaluation

image/png

Our model currently sits at TOP-5 on the VMLU benchmark

Citation

@online{t-llama,
  author = {Pham Minh Tuan},
  title = {T-Llama: A New Language Model for Vietnamese}, % Placeholder
  year = 2024,
  url = {https://github.com/vTuanpham/Vietnamese_QA_System}
}