Code Monkey home page Code Monkey logo

chinese-vicuna's Introduction

camel

Chinese-Vicuna: A Chinese Instruction-following LLaMA-based Model —— 一个中文低资源的llama+lora方案

| English | 中文 |

camel

This is the repo for the Chinese-Vicuna project, which aims to build and share an instruction-following Chinese LLaMA model which can run on a single Nvidia RTX-2080TI, that why we named this project Vicuna, small but strong enough !

  • Why is it called Vicuna:In view of the successful development of alpaca models such as llama,alpaca,guanaco,We want to train a Chinese small alpaca like Vicuna.

The repo contains:

  • code for finetune the model
  • code for generation based on trained model
  • code for run on CPU (fp16 or int4 is support, in purely C++)
  • tools to download/convert original facebook llama.ckpt

What‘s New

  • March 23, 2023:Released checkpoint-4000 with 50w data training
  • March 23, 2023:Deploy the code for fine-tuning and inferencing in colab
  • March 23, 2023:Provides code that can be used for inference in pure c++
  • March 24, 2023:Released checkpoint-8000 with 100w data training

Overview

We currently select the combination of BELLE and Guanaco data as our main training dataset. We will also add more chitchat dataset ( e.g. LCCC ) to support casual conversation.

What is the meaning?

Similar to the explosion of the stable diffusion model, platforms like civitai have emerged, consisting of a base model + various LORA models in an open source community.

The repo hopes to help you to train these LORA models.

what is LORA?:Simply, it's a plugin used to help adapt large models to your dataset, technical details can be found inLoRA: Low-Rank Adaptation of Large Language Models。Its advantage is that the finetune is very fast when it comes to getting a small model, about 30M, and the key is that it supports Plug and Play. As can be expected, this is a very suitable architecture for open source ecology.

Here, we will help you train through a very low-demand environment, with only one 2080 (11G) to achieve certain results.

Try on colab

colab link Descriptions
Open In Colab Use the specified lora model to inference and generate a webui
Open In Colab Finetune with the data we collected

Performance

Checkpoint-4000

Human Chinese-Vicuna
生成一份python的排序代码 A:def sort_list(lst):
lst.sort()
return lst
自然语言处理是什么 自然语言处理是一种计算机科学领域,旨在使计算机能够理解和处理自然语言。
能给我讲一段笑话吗 为什么猫吃鱼?因为它们喜欢游泳。
将下面文字翻译成英文。猫喜欢吃鱼,所以它们会游泳 Cats like to eat fish, so they will swim.
233和122的和等于多少 233和122的和等于355。
华为是一家怎样的公司 华为是一家全球范围内最大的移动通信设备制造商之一,以及一家全球范围内最大的移动通信设备制造商之一。华为公司的业务涵盖包括移动通信设备、互联网设备、智能家居设备等。
我想和女朋友在北京约会,能推荐几个约会的地方吗 北京有很多约会的地方,可以推荐以下几个约会的地方:

1. 北京艺术博物馆
2. 颐和园
3. 北京故宫博物馆
4. 北京***广场
5. 颐和园风景区
用python写一个二分查找的代码 ```python
def binary_search(arr, target):
low = 0
high = len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1
怎么让自己精力充沛,列5点建议 1. 保持良好的睡眠习惯;2. 定期锻炼身体;3. 学习新技能或知识;4. 与家人和朋友交流;5. 多听放松音乐。
父母都姓吴,取一些男宝宝和女宝宝的名字 男宝宝可以是吴杰、吴伟、吴飞、吴荣等。女宝宝可以是吴华、吴秀、吴美、吴婷等。
  • This LORA model is the result of 30 hours of training with a 2080Ti (checkpoint-4000), about 50w data

Checkpoint-8000

Human Chinese-Vicuna Note
写一篇英文散文诗,主题是春雨,想象自己是春雨,和英国古代诗人莎士比亚交流 A: Spring rain falls softly on my face,
A cool breeze blows through my hair,
The sun shines brightly in the sky,
And I feel as if I am flying high.

The birds chirp happily in the trees,
The flowers bloom and their scent fills the air,
The bees buzz gently from flower to flower,
And the world seems to come alive once more.

I can hear the rush of the river,
The sound of the waterfalls,
The splash of the raindrops on the rocks,
And the gentle murmur of the stream.

My heart is filled with joy and peace,
As I take in the beauty around me,
The warmth of the sun on my skin,
And the freshness of the spring air.
Repetition Penalty=2.2
写一篇英文散文诗,主题是春雨,想象自己是春雨,和英国古代诗人莎士比亚交流 春雨滴滴滚滚,
滚滚滚滚滚滚。
滚滚滚滚滚滚,
滚滚滚滚滚滚。

春雨滚滚滚,
滚滚滚滚滚滚。
滚滚滚滚滚滚,
滚滚滚滚滚滚。

春雨滚滚滚,
滚滚滚滚滚滚。
滚滚滚滚滚滚,
滚滚滚滚滚滚。

春雨滚滚滚,
滚滚滚
Repetition Penalty=1.0
Spring rain falls softly on my face,
A cool breeze blows through my hair,
The sun shines brightly in the sky,
And I feel as if I am flying high.

The birds chirp happily in the trees,
The flowers bloom and their scent fills the air,
The bees buzz gently from flower to flower,
And the world seems to come alive once more.

I can hear the rush of the river,
The sound of the waterfalls,
The splash of the raindrops on the rocks,
And the gentle murmur of the stream.

My heart is filled with joy and peace,
As I take in the beauty around me,
The warmth of the sun on my skin,
And the freshness of the spring air.
把上面的散文诗翻译成中文
春雨轻轻洒落在我的脸上,
轻轻的风轻轻吹过我的头发,
阳光明媚地照耀在天空,
我感觉自己在飞高。

鸟儿在树枝上唱歌,
花朵开放,它们的香气充满了空气,
蜜蜂在花朵间飞舞,
它们的鸣声充满了温暖。

我听到河流的声音,
水瀑在岩石上轻轻滴滴,
雨水在石头上轻轻滴滴,
它们的声音充满了宁静。

我的心充满了喜悦和平,
我感受到热浪的阳光,
温暖的空气洒在我的脸上,
我感受到春季的美
beams=2,max tokens=350
Classify the sentiment of the following sentence into Positive, Neutral, or Negative:
Super excited about teaching Stanford’s first course on Large Language Models! Check the syllabus out here
Positive
今天天气怎么样,把这句话翻译成英语 What's the weather like today?
今天天气怎么样,把这句话翻译成日语 今天の天気は何ですか?
明天就假期结束了,有点抗拒上班,应该什么办? 明天就假期结束了,有点抗拒上班,应该什么办?可以考虑一些有趣的活动,比如去看电影、阅读书籍、听音乐、去游泳池或者参加户外活动等。此外,也可以考虑一些家庭活动,比如做烹饪、做玩具、做手工艺品等。
Tell me five words that rhyme with 'shock'. Five words that rhyme with'shock' are:
1. Rock
2. Lock
3. Cock
4. Hock
5. Stock
  • We can find that you do not punish him a little, he will mess up, if the generation effect is not good, you can increase the Repetition Penalty, beams, topk.
  • If your input is long, we suggest you can turn down the beams
  • The current model has some Japanese language skills, but not strong

What we need?

  • code:

    • This code is developed based on alpaca-lora,https://github.com/tloen/alpaca-lora
    • This is a relatively simple set of code, the basic idea is to use PEFT's lora interface + transformer's trainer + instruction data configuration
  • data:

    • We have utilized several current high quality open source data and are very grateful for their contributions. Many of these data use chatgpt's interface like alpaca to generate high quality INSTRUCTION data.

    • The data format is relatively simple, basically as follows, with simple examples such as:./sample/merge_sample.json

      • {
        'instruction': 
        'input': 
        'output'
        }
        
      • That is, an instruction, an input, and an output are required. since the data is processed by directly linking instruction and input, the data can actually require only instruction and output, as

         {
          'instruction': "用一句话描述地球为什么是独一无二的。\\n\n"
          'input': ""
          'output': "地球上有适宜生命存在的条件和多样化的生命形式。"
          }
        
    • The data we currently integrate is available for download on BaiduDownload or Google Drive

  • Large Language Model:

    • LLAMA 7B(Of course, if you have a larger machine(such as 3090Ti) can be replaced with a 13B, LLAMA13B is numerically superior to 175B GPT3)
  • LORA model:

  • Device:

    • Training:A 2080Ti is sufficient. Since the data length is within 256, it takes about 9G of video memory.
      • 70w of data, 3 epochs, a 2080Ti about 200h
    • Inference:A 2080Ti is all you need。
    • CPU Inference is also support! please go to see tools

How to use

Installation

git clone https://github.com/Facico/Chinese-Vicuna
pip install -r requirements.txt

Local python environment is 3.8, torch is 1.13.1, CUDA is 12

Multi-gpu Training

bash finetune.sh
  • The parameters to note here are as follows
    • TOT_CUDA, fill in the GPU number to be used, such as TOT_CUDA="0,1,2,3"
    • PORT, fill in the corresponding port
    • DATA_PATH,fill in the corresponding data location in the format of json
    • OUTPUT_PATH,fill in the relative path to save the model
    • MODEL_PATH,path of LLM
    • wandb:This is a training visualization tool that is not turned on by default in the script, and can be turned on by adding "--wandb" to the script

Single-gpu Training

python finetune.py --data_path merge.json --test_size 2000
  • The test_size cannot be larger than the data size

inference and use gradio to generate a web page

bash generate.sh
  • The parameters to note here are as follows

    • BASE_MODEL,path of LLM
    • LORA_PATH,The checkpoint folder of the lora model
      • It should be noted here that the config loaded by the lora model must be "adapter_config.json" and the model name must be "adapter_model.bin", but it will be automatically saved as "pytorch_model.bin" during training. pytorch_model.bin" during training, while "adapter_config.json" and "adapter_model.bin" will be saved after all training is finished
        • If you load the lora model in the training checkpoint, the code will automatically copy the local "config-sample/adapter_config.json" to the corresponding directory for you and rename the "pytorch_model.bin" to "adapter_model.bin". and rename "pytorch_model.bin" to "adapter_model.bin".
  • When using, "max_tokens" is set according to your computer's video memory, and if the generated content generates a lot of duplicate information, you can turn up the "Repetition Penalty".

inference on CPU with pure C++

Details in tools readme

More Tools

We also offer:

  • ways for faster weight download ( 8MB/s ) : link
  • convert tools between the original facebook checkpoint (consolidated.xx.pth) and huggingface format (pytorch_model-000xx-of-000xx.bin): link

todo

  • belle+guanaco(1.5 epoch, 8000 step)
  • belle+guanaco(100%)
  • Add more chitchat-like conversational corpus to enhance free conversation
  • Add colab training + lora loading interface
  • Add the interaction capabilities
  • Add llama c++ inference

Citation

If you find this project useful in your research, please consider citing:

@inproceedings{leng2023chinese-vicuna,
  title={Chinese-Vicuna: A Chinese Instruction-following LLaMA-based Model},
  author={Chenghao Fan, Zhenyi Lu and Jie Tian},
  url={https://github.com/Facico/Chinese-Vicuna},
  year={2023}
}

chinese-vicuna's People

Contributors

facico avatar lzy-the-boys avatar chuge0335 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.