Skip to content
Merged

Dev #242

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
</table>

## 🎇最近更新

- 【2024.05.08】EmoLLM**爹系男友阅览体验版**上线 [1. **百度AppBuilder**](https://appbuilder.baidu.com/s/4cLyw) [2. **OpenXLab**](https://openxlab.org.cn/apps/detail/chg0901/EmoLLM3.0_Gradio_Llama3-8B-Instruct3.0), 欢迎点赞收藏
- 【2024.05.07】[增量预训练指南](xtuner_config/pt/README.md)
- 【2024.05.04】基于LLaMA3_8b_instruct的[EmoLLM3.0 OpenXLab Demo](https://st-app-center-006861-9746-jlroxvg.openxlab.space/)上线([重启链接](https://openxlab.org.cn/apps/detail/chg0901/EmoLLM-Llama3-8B-Instruct3.0)), [**LLAMA3微调指南**](xtuner_config/README_llama3_8b_instruct_qlora_alpaca_e3_M.md)**更新**,在[**OpenXLab**](https://openxlab.org.cn/models/detail/chg0901/EmoLLM-Llama3-8B-Instruct3.0)和[**ModelScope**](https://modelscope.cn/models/chg0901/EmoLLM-Llama3-8B-Instruct3.0/summary)平台发布**LLaMA3_8b_instruct-8B QLoRA微调模型 EmoLLM3.0权重**
- 【2024.04.20】[LLAMA3微调指南](xtuner_config/README_llama3_8b_instruct_qlora_alpaca_e3_M.md)及基于[LLaMA3_8b_instruct的艾薇](https://openxlab.org.cn/models/detail/ajupyter/EmoLLM-LLaMA3_8b_instruct_aiwei)开源
Expand Down Expand Up @@ -178,6 +180,7 @@
- [🎨微调指南](#微调指南)
- [🔧部署指南](#部署指南)
- [⚙RAG(检索增强生成)](#rag检索增强生成)
- [🎓评测指南](#评测指南)
- [使用到的框架](#使用到的框架)
- [如何参与本项目](#如何参与本项目)
- [作者(排名不分先后)](#作者排名不分先后)
Expand Down Expand Up @@ -205,7 +208,8 @@ git clone https://github.com/SmartFlowAI/EmoLLM.git
- [数据构建](#数据构建)
- [微调指南](#微调指南)
- [部署指南](#部署指南)
- [RAG](#rag检索增强生成pipeline)
- [RAG](#rag检索增强生成)
- [评测指南](#评测指南)
- 查看更多详情


Expand Down Expand Up @@ -234,6 +238,10 @@ git clone https://github.com/SmartFlowAI/EmoLLM.git

- 详见[RAG](rag/README.md)

### 🎓评测指南

- 本模型评测分为通用评测和专业评测,请阅读[评测指南](evaluate/README.md)查阅

<details>
<summary>更多详情</summary>

Expand Down
14 changes: 11 additions & 3 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ The Model aims to fully understand and promote the mental health of individuals,
</table>

## Recent Updates
- [2024.05.07][Incremental Pre-training Guide](xtuner_config/pt/README.md)

- [2024.05.08] EmoLLM**Daddy-like BF V0.1** is public now in [1. **Baidu AppBuilder**](https://appbuilder.baidu.com/s/4cLyw) and [2. **OpenXLab**](https://openxlab.org.cn/apps/detail/chg0901/EmoLLM3.0_Gradio_Llama3-8B-Instruct3.0), welcome to like and add it to your collections!
- [2024.05.07] [Incremental Pre-training Guide](xtuner_config/pt/README.md)
- [2024.05.04] [EmoLLM3.0 OpenXLab Demo](https://st-app-center-006861-9746-jlroxvg.openxlab.space/) based on LLaMA3_8b_instruct is available now ([restart link]((https://openxlab.org.cn/apps/detail/chg0901/EmoLLM-Llama3-8B-Instruct3.0))), [LLAMA3 fine-tuning guide](xtuner_config/README_llama3_8b_instruct_qlora_alpaca_e3_M.md) is updated, LLaMA3_8b_instruct-8B QLoRA fine-tuning model EmoLLM3.0 weights are released on [**OpenXLab**](https://openxlab.org.cn/models/detail/chg0901/EmoLLM-Llama3-8B-Instruct3.0) and [**ModelScope**](https://modelscope.cn/models/chg0901/EmoLLM-Llama3-8B-Instruct3.0/summary) platforms
- [2024.04.20] [LLAMA3 fine-tuning guide](xtuner_config/README_llama3_8b_instruct_qlora_alpaca_e3_M.md) and based on [LLaMA3_8b_instruct's aiwei](https://openxlab.org.cn/models/detail/ajupyter/EmoLLM-LLaMA3_8b_instruct_aiwei) open source
- [2023.04.14] Added [Quick Start](docs/quick_start_EN.md) and Nanny level tutorial [BabyEmoLLM](Baby_EmoLLM.ipynb)
Expand Down Expand Up @@ -179,6 +181,7 @@ The Model aims to fully understand and promote the mental health of individuals,
- [🎨Fine-tuning Guide](#fine-tuning-guide)
- [🔧Deployment Guide](#deployment-guide)
- [⚙RAG (Retrieval Augmented Generation)](#rag-retrieval-augmented-generation)
- [🎓Evaluation Guide](#evaluation-guide)
- [Frameworks Used](#frameworks-used)
- [How to participate in this project](#how-to-participate-in-this-project)
- [Version control](#version-control)
Expand Down Expand Up @@ -206,7 +209,8 @@ git clone https://github.com/SmartFlowAI/EmoLLM.git
- [Data Construction](#data-construction)
- [Fine-tuning Guide](#fine-tuning-guide)
- [Deployment Guide](#deployment-guide)
- [RAG](#rag-retrieval-augmented-generation-pipeline)
- [RAG](#rag-retrieval-augmented-generation)
- [Evaluation Guide](#evaluation-guide)
- View More Details


Expand All @@ -216,7 +220,7 @@ git clone https://github.com/SmartFlowAI/EmoLLM.git

### 📌Data Construction

- Please read the [Data Construction Guide ](generate_data/tutorial_EN.md)for reference.
- Please read the [Data Construction Guide ](generate_data/tutorial_EN.md) for reference.

- The dataset used for this fine-tuning can be found at [datasets](datasets/data.json)

Expand All @@ -233,6 +237,10 @@ For details, see the [fine-tuning guide](xtuner_config/README_EN.md)

- See [RAG](rag/README_EN.md)

### 🎓Evaluation Guide

- The model evaluation is divided into **General Metrics Evaluation** and **Professional Metrics Evaluation**,Please read the [evaluation guide](evaluate/README.md) for reference.

<details>
<summary>Additional Details</summary>

Expand Down
177 changes: 177 additions & 0 deletions app_Llama3_Gradio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import gradio as gr
import os
import torch
from transformers import GemmaTokenizer, AutoModelForCausalLM
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
from threading import Thread


DESCRIPTION = '''
<div>
<h1 style="text-align: center;">EmoLLM Llama3 心理咨询室 V4.0</h1>

<p align="center">
<a href="https://github.com/SmartFlowAI/EmoLLM/">
<img src="https://st-app-center-006861-9746-jlroxvg.openxlab.space/media/cda6c1a05dc8ba5b19ad3e7a24920fdf3750c917751202385a6dbc51.png" alt="Logo" width="20%">
</a>
</p>

<div align="center">

<!-- PROJECT SHIELDS -->
[![OpenXLab_Model][OpenXLab_Model-image]][OpenXLab_Model-url]

<h2 style="text-align: center;"> EmoLLM是一系列能够支持 理解用户-支持用户-帮助用户 心理健康辅导链路的 心理健康大模型 ,欢迎大家star~⭐⭐</h2>
<p>https://github.com/SmartFlowAI/EmoLLM</p>
</div>

</div>

[OpenXLab_Model-image]: https://cdn-static.openxlab.org.cn/header/openxlab_models.svg
[OpenXLab_Model-url]: https://openxlab.org.cn/models/detail/chg0901/EmoLLM-Llama3-8B-Instruct3.0

'''

LICENSE = """
<p align="center"> Built with Meta Llama 3 </>
"""

PLACEHOLDER = """
<div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">

</div>
"""


css = """
h1 {
text-align: center;
display: block;
}
<!--
#duplicate-button {
margin: auto;
color: white;
background: #1565c0;
border-radius: 100vh;
}
-->
"""

# download internlm2 to the base_path directory using git tool
base_path = './EmoLLM-Llama3-8B-Instruct3.0'
os.system(f'git clone https://code.openxlab.org.cn/chg0901/EmoLLM-Llama3-8B-Instruct3.0.git {base_path}')
os.system(f'cd {base_path} && git lfs pull')


# Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained(base_path,trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(base_path,trust_remote_code=True, device_map="auto", torch_dtype=torch.float16).eval() # to("cuda:0")
terminators = [
tokenizer.eos_token_id,
tokenizer.convert_tokens_to_ids("<|eot_id|>")
]

def chat_llama3_8b(message: str,
history: list,
temperature: float,
max_new_tokens: int,
top_p: float
) -> str:
"""
Generate a streaming response using the llama3-8b model.
Args:
message (str): The input message.
history (list): The conversation history used by ChatInterface.
temperature (float): The temperature for generating the response.
max_new_tokens (int): The maximum number of new tokens to generate.
Returns:
str: The generated response.
"""
conversation = []

for user, assistant in history:
conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
conversation.append({"role": "user", "content": message})

input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt").to(model.device)

streamer = TextIteratorStreamer(tokenizer, timeout=10.0, skip_prompt=True, skip_special_tokens=True)

generate_kwargs = dict(
input_ids= input_ids,
streamer=streamer,
max_new_tokens=max_new_tokens,
do_sample=True,
temperature=temperature,
top_p = top_p,
eos_token_id=terminators,
)
# This will enforce greedy generation (do_sample=False) when the temperature is passed 0, avoiding the crash.
if temperature == 0:
generate_kwargs['do_sample'] = False

t = Thread(target=model.generate, kwargs=generate_kwargs)
t.start()

outputs = []
for text in streamer:
outputs.append(text)
yield "".join(outputs)



# Gradio block
chatbot=gr.Chatbot(height=450, placeholder=PLACEHOLDER, label='EmoLLM Chat')

with gr.Blocks(fill_height=True, css=css) as demo:

gr.Markdown(DESCRIPTION)
# gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
gr.ChatInterface(
fn=chat_llama3_8b,
chatbot=chatbot,
fill_height=True,
additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
additional_inputs=[
gr.Slider(minimum=0,
maximum=1,
step=0.1,
value=0.95,
label="Temperature",
render=False),
gr.Slider(minimum=128,
maximum=4096,
step=1,
value=4096,
label="Max new tokens",
render=False ),
gr.Slider(minimum=0.0,
maximum=1,
step=0.01,
value=0.8,
label="Top P",
render=False ),
# gr.Slider(minimum=128,
# maximum=4096,
# step=1,
# value=512,
# label="Max new tokens",
# render=False ),
],
examples=[
['请介绍你自己。'],
['我觉得我在学校的学习压力好大啊,虽然我真的很喜欢我的专业,但最近总是担心自己无法达到自己的期望,这让我有点焦虑。'],
['我最近总觉得自己在感情上陷入了困境,我喜欢上了我的朋友,但又害怕表达出来会破坏我们现在的关系...'],
['我感觉自己像是被困在一个无尽的循环中。每天醒来都感到身体沉重,对日常活动提不起兴趣,工作、锻炼甚至是我曾经喜欢的事物都让我觉得厌倦'],
['最近工作压力特别大,还有一些家庭矛盾']
],
cache_examples=False,
)

gr.Markdown(LICENSE)

if __name__ == "__main__":
demo.launch()


2 changes: 1 addition & 1 deletion app_web_demo-Llama3.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def prepare_generation_config():
def combine_history(prompt):
messages = st.session_state.messages
meta_instruction = (
"你是心理健康助手EmoLLM, 由EmoLLM团队打造, 是一个研究过无数具有心理健康问题的病人与心理健康医生对话的心理专家, 在心理方面拥有广博的知识储备和丰富的研究咨询经验。你旨在通过专业心理咨询, 协助来访者完成心理诊断。请充分利用专业心理学知识与咨询技术, 一步步帮助来访者解决心理问题。\n\n"
"你是心理健康助手EmoLLM, 由EmoLLM团队打造。\n\n"
)
total_prompt =f"<|start_header_id|>system<|end_header_id|>\n\n{meta_instruction}<|eot_id|>\n\n"
for message in messages:
Expand Down
2 changes: 1 addition & 1 deletion web_demo-Llama3.py
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

system prompt 简写的目的是?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆗

Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def prepare_generation_config():
def combine_history(prompt):
messages = st.session_state.messages
meta_instruction = (
"你是心理健康助手EmoLLM, 由EmoLLM团队打造, 是一个研究过无数具有心理健康问题的病人与心理健康医生对话的心理专家, 在心理方面拥有广博的知识储备和丰富的研究咨询经验。你旨在通过专业心理咨询, 协助来访者完成心理诊断。请充分利用专业心理学知识与咨询技术, 一步步帮助来访者解决心理问题。\n\n"
"你是心理健康助手EmoLLM, 由EmoLLM团队打造\n\n"
)
total_prompt =f"<|start_header_id|>system<|end_header_id|>\n\n{meta_instruction}<|eot_id|>\n\n"
for message in messages:
Expand Down