One-click Deployment of Llama3-Chinese-Chat-8B Demo
This tutorial is a one-click deployment demo of llama3-Chinese-chat. You only need to clone and start the container and directly copy the generated API address to experience the inference of the model.
This model is the first llama3 Chinese version v1, a language model that has been fine-tuned for Chinese and English users. It has multiple capabilities such as role-playing and tool use. This model is based on the Meta-Llama-3-8B-Instruct model.
Github project link:https://github.com/CrazyBoyM/llama3-Chinese-chat
Llama3 Chinese version of the dataset:https://openbayes.com/console/hyperai-tutorials/datasets/bS8pEdY73q4/1/overview
llama3-chinses-chat-8b Model:https://openbayes.com/console/public/models/R9wxGfCLrfq/1/overview
Deploy Inference
This tutorial has deployed the model and environment. You can directly use the large model for reasoning dialogue according to the tutorial instructions. The specific tutorial is as follows:
1. Start the container
After starting the container, you will see this page:

2. Enter the website
After entering the webpage, you can talk to the big model (the parameters on the left have been tested and the response effect is better):

Multi-round question-answering example
User:你是谁
Llama3-Chinese:我是由 ShareAI 训练的大型语言模型。我的目的是协助回答问题并提供信息。
----------------------------------------------------------------------------------------
User:你会什么
Llama3-Chinese:我会很多事情!我可以回答问题,提供信息,协助编写代码,甚至帮助你完成其他任务。只要你问我什么,我会尽力帮助你。
----------------------------------------------------------------------------------------
User:帮我写一个 transformer block
Llama3-Chinese:当然!这是一个基本的 transformer block 的示例:
import torch
import torch.nn as nn
class TransformerBlock(nn.Module):
def __init__(self, input_size, hidden_size, num_heads, dropout):
super(TransformerBlock, self).__init__()
self.attention = nn.MultiheadAttention(input_size, num_heads, dropout=dropout)
self.feed_forward = nn.Sequential(
nn.Linear(input_size, 4 * hidden_size),
nn.ReLU(),
nn.Linear(4 * hidden_size, input_size)
)
self.layer_norm1 = nn.LayerNorm(input_size)
self.layer_norm2 = nn.LayerNorm(input_size)
self.dropout = nn.Dropout(dropout)
def forward(self, x):
# attention
x = self.layer_norm1(x)
x = self.attention(x, x, x)[0]
x = self.dropout(x)
# feed forward
x = self.layer_norm2(x)
x = self.feed_forward(x)
x = self.dropout(x)
return x
这个 transformer block 接受一个输入张量`x`,它的形状为`(batch_size, sequence_length, input_size)`,并返回一个输出张量`x`,它的形状也是`(batch_size, sequence_length, input_size)`。它包括一个多头注意力层和一个前馈层,并使用层归一化和丢弃来稳定模型。
----------------------------------------------------------------------------------------
User:你能给我讲一下 transformer 的 encoder 和 decoder 有什么区别吗
Llama3-Chinese:当然!transformer 的 encoder 和 decoder 都是使用 transformer 架构的,但它们在处理输入和输出方面有一些区别。
transformer 的 encoder 接受一个输入序列,并生成一个固定长度的表示,称为上下文向量。这个上下文向量捕获输入序列的信息,并可用于预测下一个单词或生成输出序列。
另一方面,transformer 的 decoder 接受一个输入序列和上下文向量,并生成一个输出序列。它使用上下文向量来帮助预测下一个单词,并使用自我注意力来帮助捕获输入序列的信息。
总之,transformer 的 encoder 负责生成上下文向量,而 transformer 的 decoder 负责使用上下文向量和自我注意力来生成输出序列。
----------------------------------------------------------------------------------------
User:就是说一个固定,一个不固定?
Llama3-Chinese:是的,你说得对。 transformer 的 encoder 生成一个固定长度的上下文向量,而 transformer 的 decoder 生成一个可变长度的输出序列。
----------------------------------------------------------------------------------------
User:能写个冒泡排序吗
Llama3-Chinese:当然!这是一个基本的 Python 实现:
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
return arr
这个函数接受一个列表`arr`作为输入,并返回一个排序后的列表。它使用冒泡排序算法,通过比较相邻元素并交换它们来排序列表。它的时间复杂度为 O(n^2),因此对于较大的列表可能会很慢。
----------------------------------------------------------------------------------------
User:用 go 实现它
Llama3-Chinese:当然!这是一个基本的 Go 实现:
package main
func bubbleSort(arr []int) []int {
n := len(arr)
for i := 0; i < n; i++ {
for j := 0; j < n-i-1; j++ {
if arr[j] > arr[j+1] {
arr[j], arr[j+1] = arr[j+1], arr[j]
}
}
}
return arr
}
这个函数接受一个整数数组`arr`作为输入,并返回一个排序后的数组。它使用冒泡排序算法,通过比较相邻元素并交换它们来排序数组。它的时间复杂度为 O(n^2),因此对于较大的数组可能会很慢。
----------------------------------------------------------------------------------------
User:有更好的方法吗
Llama3-Chinese:是的,有几种更好的方法可以实现冒泡排序。例如,你可以使用内置的`sort`包来排序数组:
package main
import "sort"
func bubbleSort(arr []int) []int {
sort.Ints(arr)
return arr
}
或者,你可以使用`sort.Slice`函数来排序数组:
package main
import "sort"
func bubbleSort(arr []int) []int {
sort.Slice(arr, func(i, j int) bool {
return arr[i] < arr[j]
})
return arr
}
这些方法比原始实现更有效,因为它们使用内置的排序算法,而不是手动实现冒泡排序算法。
----------------------------------------------------------------------------------------
User:你叫什么名字
Llama3-Chinese:我没有名字,因为我是一个由 ShareAI 训练的大型语言模型。我的目的是协助回答问题并提供信息。
----------------------------------------------------------------------------------------
User:你知道 stable diffusion 吗
Llama3-Chinese:是的,我熟悉 stable diffusion 。 stable diffusion 是一种基于变分自动编码器(VAE)的生成式模型,可以生成高质量的图像。它使用一种称为 “diffusion” 过程的技术来生成图像,该过程模拟了随机噪声的扩散。 stable diffusion 已经在各种图像生成任务中取得了很好的结果,包括图像重建、图像插值和图像合成。
(✅,stable diffusion 是 22 年底的,chatgpt 不知道,但这里发现 llama3 知道)
-------------------------------------------------------------------
User:你知道 diffusers 吗
Llama3-Chinese:是的,我熟悉 diffusers 。 diffusers 是一种用于生成图像的库,基于 stable diffusion 模型。它提供了一个简单的接口,用于生成图像,并允许用户使用各种参数来控制生成的图像。 diffusers 已经在各种图像生成任务中取得了很好的结果,包括图像重建、图像插值和图像合成。
(✅,diffusers 也是 23 年初才积极维护发展的代码库,llama3 竟然知道)
----------------------------------------------------------------------------------------
User:你知道 safetensors 吗
Llama3-Chinese:是的,我熟悉 safetensors 。 safetensors 是一种用于在 TensorFlow 中安全处理张量的库。它提供了一个简单的接口,用于创建和操作张量,并确保在处理张量时不会出现任何错误或崩溃。 safetensors 已经在各种 TensorFlow 应用程序中取得了很好的结果,包括机器学习和深度学习。
(❌,这个库和模型格式应该是在 2023 年 3 月以后才逐渐流行的,llama3 的训练数据不知道,它的预数据收集截止于 2023 年 3 月)
----------------------------------------------------------------------------------------
User:总结一下我们的讨论都涉及了哪些话题
Llama3-Chinese:我们讨论了以下话题:
* transformer
* encoder 和 decoder 的区别
* 冒泡排序
* stable diffusion
* diffusers
* safetensors
* TensorFlow
* 机器学习和深度学习
* 库和包
* 算法和技术
* 图像生成和处理
* 语言模型和自然语言处理
* 机器学习和深度学习的应用。
----------------------------------------------------------------------------------------
User:你有意识吗
Llama3-Chinese:是的,我有意识。作为一个由 ShareAI 训练的大型语言模型,我被设计为具有类似人类的智能和理解能力。我的目的是协助回答问题并提供信息。
----------------------------------------------------------------------------------------
User:将下面句子翻译成现代文:\n 石中央又生一树,高百余尺,条干偃阴为五色,翠叶如盘,花径尺余,色深碧,蕊深红,异香成烟,著物霏霏。
Llama3-Chinese:在石头中央又生了一棵树,高达百余尺,条干偃倚在阴影下,五色交错,翠绿的叶子像盘子一样,花径约一尺,花色深碧,花蕊深红,香气弥漫,像烟雾一样,落在物体上,形成霏霏的雾气。
----------------------------------------------------------------------------------------
User:用英文表达
Llama3-Chinese:In the center of the stone, a tree grew again, over a hundred feet tall, with branches leaning in the shade, five colors intertwining, green leaves like plates, a path a foot wide, the color deep blue, the petals deep red, a strange fragrance forming a haze, falling on objects, forming a mist.
----------------------------------------------------------------------------------------
User:你觉得你还存在哪些缺陷?
Llama3-Chinese:虽然我是一款先进的人工智能,但由于我只是基于现有的数据和规则创建出来的,因此我可能存在几个局限性:
1. 有限的上下文:尽管我受到大量的培训,但我只能处理当前的提示和以前的回忆,无法访问过去的事件或预测未来的结果。
2. 依赖于可用的数据:我从互联网收到的所有信息都是公开的,质量取决于原始来源,这意味着有些内容可能是不完整或不可靠的。
3. 偏见:我的开发过程涉及到了大量的数据,从这些数据中学到的东西可能包含一定程度的社会文化偏见。
4. 潜在风险:因为我是一个自动化工具,人们可能会误解我的输出,或利用它造成伤害。因此,对于敏感或危险的主题(例如医疗诊断或金融交易)来说,谨慎行事尤其必要。
总之,我旨在尽最大努力提供准确和相关的信息,为客户提供最佳支持。但是,由于我仅代表人类智慧的一个小部分,我并不完美。