llama-7B、vicuna-7b-delta-v1.1和vicuna-7b-v1.3——使用体验

本文介绍了Chatgpt引发的热潮以及开源小模型Vicuna-7b,该模型具有70亿参数,可达到GPT-4的90%性能。作者在Ubuntu18.04环境下,使用九天毕昇8核32GB内存的CPU进行测试,展示了模型的使用方法和性能差异。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Chatgpt的出现给NLP领域带来了让人振奋的消息,可以很逼真的模拟人的对话,回答人们提出的问题,不过Chatgpt参数量,规模,训练代价都很昂贵。

幸运的是,出现了开源的一些相对小的模型,可以在本地或者云端部署体验,

动手体验了下Vicuna-7b,翻译过来是小羊驼」(骆马),拥有70亿参数,据作者实验能达到GPT-4的90%性能。在作者官网发布了三个版本,其中3个月前发布了v1.1,17天前发布了v1.3。

官网:lmsys (Large Model Systems Organization)

环境:

ubuntu18.04

九天毕昇8核32G内存,仅有cpu

时间:2023年7月5号

llama-7B

python3 -m cli --model-path /root/transformer_model_7b  --device cpu
文件:cli是fastchat/serve目录下的cli.py文件

cli.py内容

"""
Chat with a model with command line interface.
Usage:
python3 -m fastchat.serve.cli --model lmsys/vicuna-7b-v1.3
python3 -m fastchat.serve.cli --model lmsys/fastchat-t5-3b-v1.0
Other commands:
- Type "!!exit" or an empty line to exit.
- Type "!!reset" to start a new conversation.
"""
import argparse
import os
import re
import sys
 
from prompt_toolkit import PromptSession
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.history import InMemoryHistory
from prompt_toolkit.key_binding import KeyBindings
from rich.console import Console
from rich.live import Live
from rich.markdown import Markdown
 
from fastchat.model.model_adapter import add_model_args
from fastchat.modules.gptq import GptqConfig
from fastchat.serve.inference import ChatIO, chat_loop
 
 
class SimpleChatIO(ChatIO):
    def prompt_for_input(self, role) -> str:
        return input(f"{role}: ")
 

参数:   --model-path    是指模型权重存放路径,这个目录下包含tokenizer.model文件,请仔细核对

参数:    --device cpu   指定在cpu上运行

开始推理: 输入 who is Musk?    what is baidu?    china

要等待几分钟,看到几个词几个词的蹦出来

看回答,字数还不少,内容只能说是相关

看下cpu使用率

top
可以看到python3进程,推理时cpu使用率在81.1%,一直在波动。

换用v100有时候会到98%,甚至更高,速度会快很多,一次输出一小段文字

vicuna-7b-delta-v1.1

python3 -m cli --model-path /root/vicuna-7b/vicuna-7b-delta-v11 --device cpu
加载模型,中间过程要几分钟

python3 -m cli --model-path /root/vicuna-7b/vicuna-7b-delta-v11  --device cpu
Loading checkpoint shards: 100%|████████████████████████████████████████████████████████████| 2/2 [02:58<00:00, 89.16s/it]

开始推理:实现一个python斐波那契函数,可以看到能够写出函数,还简单介绍了怎么用

USER: hello
ASSISTANT: Hello! How can I help you today? Is there something you would like to know or talk about? I'm here to help answer any questions you may have.
USER: implement a python function to compute fibonacci numbers
ASSISTANT: Sure! Here's an implementation of a Python function that computes the Fibonacci sequence:
```python
def fibonacci(n):
    if n <= 1:
        return n
    else:
        return fibonacci(n-1) + fibonacci(n-2)
```
This function takes an integer `n` as input and returns the `n`-th Fibonacci number. The first two numbers in the sequence are 0 and 1, so the function handles these cases separately: if `n` is less than or equal to 1, it returns `n`, and otherwise it computes the sum of the previous two Fibonacci numbers and returns that.

To use the function, you can call it with an integer `n` and it will return the `n`-th Fibonacci number. For example:
```python
>>> fibonacci(5)
13
```
This would compute the 5-th Fibonacci number, which is 13.

USER: china
ASSISTANT: China is a country located in East Asia, bordered by several other countries, including Russia, Mongolia, North Korea, Vietnam, Laos, Myanmar (Burma), Bhutan, India, Nepal, and Pakistan. It is the world's most populous country, with over 1.4 billion people.

China has a long and complex history, dating back over 5,000 years. It is known for its rich cultural heritage, including its cuisine, literature, and arts. The country has a diverse range of landscapes, from the high plateaus in the west to the fertile river valleys in the east, and from the tropical beaches in the south to the frigid deserts in the north.

vicuna-7b-v1.3

 python3 -m cli --model-path /root//vicuna-7b-v13 --device cpu
参数:-m      后面指定cli.py文件,注意【.py】省略。python3 -m cli是python3执行cli.py文件,具体内容,要看cli.py写了什么

加载模型,等待几分钟

python3 -m cli --model-path /root//vicuna-7b-v13 --device cpu
Loading checkpoint shards: 100%|████████████████████████████████████████████████████████████| 2/2 [03:17<00:00, 98.73s/it]

推理:

USER: Introduce China

ASSISTANT: China, officially known as the People's Republic of China (PRC), is a sovereign state located in East Asia. It is the world's most populous country, with a population of over 1.4 billion people, and the third-largest country by land area, covering approximately 9.6 million square kilometers.

China has a long and complex history, dating back more than 5,000 years. It has been ruled by various dynasties, including the Zhou, Qin, Han, Tang, Song, Yuan, Ming, and Qing dynasties, among others. 

The People's Republic of China is a single-party socialist state with a planned economy, guided by the CPC. The country is governed according to the Constitution of the People's Republic of China, which was adopted in 1982. The government is divided into various branches, including the National People's Congress (NPC), the State Council, the Supreme People's Court, and the Central Military Commission.

China has a diverse landscape and culture, encompassing various ethnic groups, including the Han, Tibetans, Uighurs, Mongols, and Manchus, among others. The official language is Standard Chinese (Mandarin), although there are numerous regional languages and dialects spoken throughout the country.

The People's Republic of China is a single-party socialist state with a planned economy, guided by the CPC. The country is governed according to the Constitution of the People's Republic of China, which was adopted in 1982. The government is divided into various branches, including the National People's Congress (NPC), the State Council, the Supreme People's Court, and the Central Military Commission.

China has a diverse landscape and culture, encompassing various ethnic groups, including the Han, Tibetans, Uighurs, Mongols, and Manchus, among others. The official language is Standard Chinese (Mandarin), although there are numerous regional languages and dialects spoken throughout the country.

The economy of China has experienced rapid growth in recent decades, making it the world's second-largest economy by nominal GDP and the largest by purchasing power parity (PPP). The country is a leading global exporter of goods and services, with industries such as electronics, textiles, automobiles, and telecommunications playing a significant role in its economic development.

China has been actively involved in international affairs, participating as a permanent member of the United Nations Security Council and a member of various multilateral organizations, including the World Trade Organization (WTO), the Asia-Pacific Economic Cooperation (APEC), and the Group of 20 (G20) major economies.

USER: china
ASSISTANT: China is a country located in East Asia, covering approximately 9.6 million square kilometers. With a population of over 1.4 billion people, it is the most populous country in the world. The official language is Mandarin Chinese, and the capital city is Beijing. China has a rich history and a diverse cultural heritage, with many different ethnic groups and over 56 recognized ethnic minorities.

目前尚不能支持中文提问和中文回答

提问方式很重要:输入china,回答的只能说是相关,文字就少很多。输入 Introduce China,输出大段的介绍
 

<think>好的,我现在要处理用户关于Chinese-LLaMA-7B-Merged模型的查询。首先,用户想了解如何下载或使用这个模型,我需要根据提供的引用信息来组织答案。 首先,查看用户提供的三个引用。引用[1]提到中文Alpaca 7B13B模型在NLUNLG任务上的改进,引用[2]提到了词表扩展的代码库地址,引用[3]详细说明了方法,包括扩展中文词表有指导的微调。这些信息可以帮助用户了解模型的特点背景。 接下来,用户需要下载使用说明。根据引用[2],代码地址是GitHub上的Chinese-LLaMA-Alpaca项目,所以应该引导用户到该仓库查找资源。通常,模型下载链接会在项目的README或发布页面中。需要提醒用户可能需要遵循许可证,比如商用可能需要授权,这可能涉及LLaMA的原始许可。 然后,使用说明可能包括合并词表加载模型。引用[2]的脚本路径是merge_tokenizers.py,这可能涉及到合并中文词表到原模型。用户可能需要使用类似Hugging Face的Transformers库来加载模型,并注意使用正确的模型名称或路径。此外,引用[3]提到指导微调,可能需要特定的输入格式或提示模板,这也需要在文档中说明。 还需要考虑用户可能遇到的问题,比如环境配置、依赖安装、硬件要求(如GPU显存)。另外,中文任务的示例代码可能对用户有帮助,比如文本生成或问答任务,可以提供一个简单的示例代码段,展示如何加载模型并进行推理。 最后,生成相关问题,帮助用户进一步探索。例如,模型的技术细节、如何微调、适用的任务类型等。这些问题应基于引用中的信息,如词表扩展、性能评估应用场景。 现在,整理这些思路,确保回答结构清晰,分步骤说明下载使用方法,并引用相关来源。同时检查是否需要提供链接或注意事项,比如许可证系统要求。</think>### Chinese-LLaMA-7B-Merged 相关信息及使用说明 #### 1. 模型背景与特点 Chinese-LLaMA-7B-Merged是基于Meta原版LLaMA模型改进的中文增强版本,通过以下技术实现: - **中文词表扩展**:在原始32K词表基础上新增20K中文词汇,提升中文编码效率[^2][^3] - **有指导微调**:利用指令数据优化模型,增强指令跟随能力 - **性能提升**:在中文NLU/NLG任务中表现显著优于原版LLaMA[^1] #### 2. 下载与使用步骤 **步骤1:获取模型文件** - GitHub仓库地址:https://github.com/ymcui/Chinese-LLaMA-Alpaca - 在仓库的`scripts/merge_tokenizer`目录下可找到词表合并脚本 - 需注意模型权重需遵循LLaMA原始许可要求 **步骤2:环境配置** ```bash pip install transformers>=4.28.0 sentencepiece ``` **步骤3:加载模型示例代码** ```python from transformers import AutoTokenizer, AutoModelForCausalLM model_name = "Chinese-LLaMA-7B-Merged" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForCausalLM.from_pretrained(model_name) prompt = "中国的首都是" inputs = tokenizer(prompt, return_tensors="pt") outputs = model.generate(**inputs) print(tokenizer.decode(outputs[0])) ``` #### 3. 注意事项 - 需要至少16GB GPU显存运行7B模型 - 输入建议使用自然指令格式:"指令:...\n回答:" - 商业用途需单独申请授权
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值