Skip to content

Commit eac7f97

Browse files
committed
release v0.1.0
Former-commit-id: 63c8d3a
1 parent c08ff73 commit eac7f97

30 files changed

Lines changed: 1517 additions & 313 deletions

README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
## Changelog
1212

13-
[23/07/11] Now we support training the **Baichuan-13B** model in this repo. Try `--model_name_or_path baichuan-inc/Baichuan-13B-Base`, `--padding_side right` and `--lora_target W_pack` arguments to train the Baichuan-13B model. Remember to use `--prompt_template baichuan` argument when you are using the Baichuan-13B-Chat model.
13+
[23/07/18] Now we develop an all-in-one Web UI for training, evaluation and inference. Try `train_web.py` to fine-tune models in your Web browser. Thank [@KanadeSiina](https://github.com/KanadeSiina) and [@codemayq](https://github.com/codemayq) for their efforts in the development.
14+
15+
[23/07/11] Now we support training the **Baichuan-13B** model in this repo. Please replace the Baichuan-13B model file with `tests/modeling_baichuan.py` and try `--model_name_or_path path_to_baichuan_model` and `--lora_target W_pack` arguments to train the Baichuan-13B model. Remember to use `--prompt_template baichuan` argument when you are using the Baichuan-13B-Chat model.
1416

1517
[23/07/09] Now we release [FastEdit](https://github.com/hiyouga/FastEdit)⚡🩹, an easy-to-use package for editing the factual knowledge of large language models efficiently. Please follow [FastEdit](https://github.com/hiyouga/FastEdit) if you are interested.
1618

@@ -125,14 +127,10 @@ cd LLaMA-Efficient-Tuning
125127
pip install -r requirements.txt
126128
```
127129

128-
### LLaMA Weights Preparation (optional)
129-
130-
1. Download the weights of the LLaMA models.
131-
2. Convert them to HF format using the following command.
130+
### All-in-one Web UI
132131

133132
```bash
134-
python -m transformers.models.llama.convert_llama_weights_to_hf \
135-
--input_dir path_to_llama_weights --model_size 7B --output_dir path_to_llama_model
133+
python src/train_web.py
136134
```
137135

138136
### (Continually) Pre-Training
@@ -275,10 +273,20 @@ CUDA_VISIBLE_DEVICES=0 python src/train_bash.py \
275273

276274
We recommend using `--per_device_eval_batch_size=1` and `--max_target_length 128` at 4/8-bit evaluation.
277275

278-
### API / CLI / Web Demo
276+
### API Demo
277+
278+
```bash
279+
python src/api_demo.py \
280+
--model_name_or_path path_to_your_model \
281+
--checkpoint_dir path_to_checkpoint
282+
```
283+
284+
See `http://localhost:8000/docs` for API documentation.
285+
286+
### CLI Demo
279287

280288
```bash
281-
python src/xxx_demo.py \
289+
python src/cli_demo.py \
282290
--model_name_or_path path_to_your_model \
283291
--checkpoint_dir path_to_checkpoint
284292
```

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ transformers>=4.29.1
33
datasets>=2.12.0
44
accelerate>=0.19.0
55
peft>=0.3.0
6-
trl==0.4.4
6+
trl>=0.4.7
77
sentencepiece
88
jieba
99
rouge-chinese
1010
nltk
1111
gradio>=3.36.0
1212
uvicorn
13-
pydantic==1.10.7
13+
pydantic
1414
fastapi
1515
sse-starlette
1616
matplotlib

src/llmtuner/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from llmtuner.api import create_app
22
from llmtuner.chat import ChatModel
33
from llmtuner.tuner import get_train_args, get_infer_args, load_model_and_tokenizer, run_pt, run_sft, run_rm, run_ppo
4+
from llmtuner.webui import create_ui
45

56

6-
__version__ = "0.0.9"
7+
__version__ = "0.1.0"

src/llmtuner/api/app.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import uvicorn
23
from fastapi import FastAPI, HTTPException
34
from fastapi.middleware.cors import CORSMiddleware
@@ -93,7 +94,7 @@ async def predict(query: str, history: List[Tuple[str, str]], prefix: str, reque
9394
finish_reason=None
9495
)
9596
chunk = ChatCompletionStreamResponse(model=request.model, choices=[choice_data], object="chat.completion.chunk")
96-
yield chunk.json(exclude_unset=True, ensure_ascii=False)
97+
yield json.dumps(chunk, ensure_ascii=False)
9798

9899
for new_text in chat_model.stream_chat(
99100
query, history, prefix, temperature=request.temperature, top_p=request.top_p, max_new_tokens=request.max_tokens
@@ -107,15 +108,15 @@ async def predict(query: str, history: List[Tuple[str, str]], prefix: str, reque
107108
finish_reason=None
108109
)
109110
chunk = ChatCompletionStreamResponse(model=request.model, choices=[choice_data], object="chat.completion.chunk")
110-
yield chunk.json(exclude_unset=True, ensure_ascii=False)
111+
yield json.dumps(chunk, ensure_ascii=False)
111112

112113
choice_data = ChatCompletionResponseStreamChoice(
113114
index=0,
114115
delta=DeltaMessage(),
115116
finish_reason="stop"
116117
)
117118
chunk = ChatCompletionStreamResponse(model=request.model, choices=[choice_data], object="chat.completion.chunk")
118-
yield chunk.json(exclude_unset=True, ensure_ascii=False)
119+
yield json.dumps(chunk, ensure_ascii=False)
119120
yield "[DONE]"
120121

121122
return app

src/llmtuner/extras/constants.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,27 @@
55
FINETUNING_ARGS_NAME = "finetuning_args.json"
66

77
LAYERNORM_NAMES = ["norm", "ln_f", "ln_attn", "ln_mlp"] # for LLaMA, BLOOM and Falcon settings
8+
9+
METHODS = ["full", "freeze", "lora"]
10+
11+
SUPPORTED_MODELS = {
12+
"LLaMA-7B": "huggyllama/llama-7b",
13+
"LLaMA-13B": "huggyllama/llama-13b",
14+
"LLaMA-30B": "huggyllama/llama-30b",
15+
"LLaMA-65B": "huggyllama/llama-65b",
16+
"BLOOM-560M": "bigscience/bloom-560m",
17+
"BLOOM-3B": "bigscience/bloom-3b",
18+
"BLOOM-7B1": "bigscience/bloom-7b1",
19+
"BLOOMZ-560M": "bigscience/bloomz-560m",
20+
"BLOOMZ-3B": "bigscience/bloomz-3b",
21+
"BLOOMZ-7B1-mt": "bigscience/bloomz-7b1-mt",
22+
"Falcon-7B-Base": "tiiuae/falcon-7b",
23+
"Falcon-7B-Chat": "tiiuae/falcon-7b-instruct",
24+
"Falcon-40B-Base": "tiiuae/falcon-40b",
25+
"Falcon-40B-Chat": "tiiuae/falcon-40b-instruct",
26+
"Baichuan-7B": "baichuan-inc/Baichuan-7B",
27+
"Baichuan-13B-Base": "baichuan-inc/Baichuan-13B-Base",
28+
"Baichuan-13B-Chat": "baichuan-inc/Baichuan-13B-Chat",
29+
"InternLM-7B-Base": "internlm/internlm-7b",
30+
"InternLM-7B-Chat": "internlm/internlm-chat-7b"
31+
}

src/llmtuner/extras/logging.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22
import logging
33

44

5+
class LoggerHandler(logging.Handler):
6+
7+
def __init__(self):
8+
super().__init__()
9+
self.log = ""
10+
11+
def emit(self, record):
12+
if record.name == "httpx":
13+
return
14+
log_entry = self.format(record)
15+
self.log += log_entry
16+
self.log += "\n\n"
17+
18+
519
def get_logger(name: str) -> logging.Logger:
620

721
formatter = logging.Formatter(

src/llmtuner/extras/ploting.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import math
23
import json
34
import matplotlib.pyplot as plt
45
from typing import List, Optional
@@ -10,12 +11,13 @@
1011
logger = get_logger(__name__)
1112

1213

13-
def smooth(scalars: List[float], weight: Optional[float] = 0.9) -> List[float]:
14+
def smooth(scalars: List[float]) -> List[float]:
1415
r"""
1516
EMA implementation according to TensorBoard.
1617
"""
1718
last = scalars[0]
1819
smoothed = list()
20+
weight = 1.8 * (1 / (1 + math.exp(-0.05 * len(scalars))) - 0.5) # a sigmoid function
1921
for next_val in scalars:
2022
smoothed_val = last * weight + (1 - weight) * next_val
2123
smoothed.append(smoothed_val)

0 commit comments

Comments
 (0)