Convert Figma logo to code with AI

PaddlePaddle logoPaddleNLP

👑 Easy-to-use and powerful NLP and LLM library with 🤗 Awesome model zoo, supporting wide-range of NLP tasks from research to industrial applications, including 🗂Text Classification, 🔍 Neural Search, ❓ Question Answering, ℹ️ Information Extraction, 📄 Document Intelligence, 💌 Sentiment Analysis etc.

11,947
2,909
11,947
721

Top Related Projects

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.

34,658

DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.

30,129

Facebook AI Research Sequence-to-Sequence Toolkit written in Python.

11,460

A scalable generative AI framework built for researchers and developers working on Large Language Models, Multimodal, and Speech AI (Automatic Speech Recognition and Text-to-Speech)

11,728

An open-source NLP research library, built on PyTorch.

Quick Overview

PaddleNLP is an easy-to-use and powerful NLP library built on PaddlePaddle, an open-source deep learning platform. It provides a wide range of NLP tools, pre-trained models, and datasets for various natural language processing tasks. PaddleNLP aims to make NLP development more accessible and efficient for both researchers and practitioners.

Pros

  • Comprehensive collection of pre-trained models and datasets for various NLP tasks
  • Easy-to-use API with high-level abstractions for quick development
  • Seamless integration with PaddlePaddle ecosystem for efficient deep learning
  • Active development and regular updates from the community

Cons

  • Less popular compared to some other NLP libraries like Hugging Face Transformers
  • Documentation and examples may not be as extensive as more established libraries
  • Primarily focused on Chinese NLP, which may limit its applicability for some users
  • Steeper learning curve for those not familiar with PaddlePaddle framework

Code Examples

  1. Text Classification
from paddlenlp import Taskflow

text_classifier = Taskflow("text_classification")
result = text_classifier("这个产品很好用,推荐购买")
print(result)  # Output: [{'label': 'positive', 'score': 0.9991}]
  1. Named Entity Recognition
from paddlenlp import Taskflow

ner = Taskflow("ner")
result = ner("华为是一家总部位于广东省深圳市的中国大型跨国科技公司")
print(result)  # Output: [{'text': '华为', 'label': 'ORGANIZATION'}, {'text': '广东省深圳市', 'label': 'LOC'}, {'text': '中国', 'label': 'LOC'}]
  1. Sentiment Analysis
from paddlenlp import Taskflow

senta = Taskflow("sentiment_analysis")
result = senta("这家餐厅的菜品非常美味,服务态度也很好")
print(result)  # Output: [{'label': 'positive', 'score': 0.9999}]

Getting Started

To get started with PaddleNLP, follow these steps:

  1. Install PaddleNLP:
pip install --upgrade paddlenlp
  1. Import and use a pre-built task:
from paddlenlp import Taskflow

# Use a pre-built task for text classification
classifier = Taskflow("text_classification")
result = classifier("这是一个很棒的产品")
print(result)

For more advanced usage and custom models, refer to the official documentation and examples in the GitHub repository.

Competitor Comparisons

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.

Pros of transformers

  • Larger community and more extensive documentation
  • Supports a wider range of models and tasks
  • More frequent updates and releases

Cons of transformers

  • Can be more complex for beginners
  • Potentially slower inference speed for some models
  • Larger package size and dependencies

Code Comparison

transformers:

from transformers import BertTokenizer, BertModel
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
model = BertModel.from_pretrained('bert-base-uncased')
inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
outputs = model(**inputs)

PaddleNLP:

from paddlenlp.transformers import BertTokenizer, BertModel
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
model = BertModel.from_pretrained('bert-base-uncased')
inputs = tokenizer("Hello, my dog is cute", return_tensors="pd")
outputs = model(**inputs)

Both libraries offer similar functionality for working with transformer models, with slight differences in syntax and backend frameworks (PyTorch for transformers, PaddlePaddle for PaddleNLP). transformers generally has broader model support and a larger community, while PaddleNLP may offer better performance in some scenarios and is more tightly integrated with the PaddlePaddle ecosystem.

34,658

DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.

Pros of DeepSpeed

  • Highly optimized for large-scale model training and inference
  • Supports a wide range of hardware configurations, including multi-GPU and multi-node setups
  • Offers advanced features like ZeRO optimizer and pipeline parallelism

Cons of DeepSpeed

  • Steeper learning curve compared to PaddleNLP
  • Primarily focused on optimization techniques rather than providing a comprehensive NLP toolkit
  • May require more manual configuration for specific use cases

Code Comparison

DeepSpeed:

import deepspeed
model_engine, optimizer, _, _ = deepspeed.initialize(args=args,
                                                     model=model,
                                                     model_parameters=params)

PaddleNLP:

from paddlenlp.transformers import BertForSequenceClassification
model = BertForSequenceClassification.from_pretrained('bert-base-uncased', num_classes=2)

DeepSpeed focuses on optimizing model training and inference, while PaddleNLP provides a more comprehensive NLP toolkit with pre-built models and easy-to-use APIs. DeepSpeed requires more manual configuration but offers advanced optimization techniques, whereas PaddleNLP emphasizes simplicity and ease of use for NLP tasks.

30,129

Facebook AI Research Sequence-to-Sequence Toolkit written in Python.

Pros of fairseq

  • More extensive documentation and examples
  • Wider range of pre-trained models available
  • Stronger community support and contributions

Cons of fairseq

  • Steeper learning curve for beginners
  • Less focus on Chinese language processing
  • Requires more computational resources for some tasks

Code Comparison

fairseq:

from fairseq.models.transformer import TransformerModel
en2de = TransformerModel.from_pretrained('/path/to/model', checkpoint_file='model.pt')
en2de.translate('Hello world!')

PaddleNLP:

from paddlenlp.transformers import AutoModelForConditionalGeneration, AutoTokenizer
model = AutoModelForConditionalGeneration.from_pretrained("mbart-large-50-many-to-many-mmt")
tokenizer = AutoTokenizer.from_pretrained("mbart-large-50-many-to-many-mmt")

Both libraries offer similar functionality for working with transformer models, but fairseq's API is more specialized for machine translation tasks, while PaddleNLP provides a more general-purpose interface for various NLP tasks. PaddleNLP's code is often more concise and easier to read, especially for newcomers to the field.

11,460

A scalable generative AI framework built for researchers and developers working on Large Language Models, Multimodal, and Speech AI (Automatic Speech Recognition and Text-to-Speech)

Pros of NeMo

  • Specialized for conversational AI and speech tasks
  • Extensive documentation and tutorials
  • Strong GPU optimization and integration with NVIDIA hardware

Cons of NeMo

  • Limited to specific AI domains (speech, NLP)
  • Steeper learning curve for beginners
  • Requires NVIDIA GPUs for optimal performance

Code Comparison

NeMo example:

import nemo.collections.asr as nemo_asr

asr_model = nemo_asr.models.EncDecCTCModel.from_pretrained("QuartzNet15x5Base-En")
transcription = asr_model.transcribe(["audio_file.wav"])

PaddleNLP example:

from paddlenlp.transformers import ErnieTokenizer, ErnieForSequenceClassification

tokenizer = ErnieTokenizer.from_pretrained('ernie-1.0')
model = ErnieForSequenceClassification.from_pretrained('ernie-1.0')

NeMo focuses on speech recognition tasks, while PaddleNLP provides a broader range of NLP functionalities. NeMo's code is more specialized for audio processing, whereas PaddleNLP offers a more general-purpose NLP toolkit.

11,728

An open-source NLP research library, built on PyTorch.

Pros of AllenNLP

  • More extensive documentation and tutorials
  • Wider range of pre-implemented models and tasks
  • Stronger focus on research-oriented features

Cons of AllenNLP

  • Steeper learning curve for beginners
  • Less integration with deep learning frameworks other than PyTorch

Code Comparison

AllenNLP:

from allennlp.predictors import Predictor

predictor = Predictor.from_path("https://storage.googleapis.com/allennlp-public-models/bert-base-srl-2020.03.24.tar.gz")
result = predictor.predict(sentence="Did Uriah honestly think he could beat the game in under three hours?")

PaddleNLP:

from paddlenlp import Taskflow

srl = Taskflow("semantic_role_labeling")
result = srl("他叫我吃饭")

AllenNLP provides a more verbose but flexible approach, while PaddleNLP offers a simpler, more streamlined interface for common NLP tasks. AllenNLP's code demonstrates its research-oriented nature, allowing for more customization. PaddleNLP's code showcases its ease of use for quick implementations, especially for Chinese NLP tasks.

Both libraries have their strengths, with AllenNLP being more suitable for research and complex projects, while PaddleNLP excels in simplicity and Chinese language support.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

简体中文🀄 | English🌎


特性 | 模型支持 | 安装 | 快速开始 | 社区交流

PaddleNLP是一款基于飞桨深度学习框架的大语言模型(LLM)开发套件,支持在多种硬件上进行高效的大模型训练、无损压缩以及高性能推理。PaddleNLP 具备**简单易用和性能极致**的特点,致力于助力开发者实现高效的大模型产业级应用。

PaddlePaddle%2FPaddleNLP | Trendshift

News 📢

  • 2024.08.08 📚《飞桨产业级大语言模型开发利器 PaddleNLP 3.0 重磅发布》,训压推全流程贯通,主流模型全覆盖。大模型自动并行,千亿模型训推全流程开箱即用。提供产业级高性能精调与对齐解决方案,压缩推理领先,多硬件适配。覆盖产业级智能助手、内容创作、知识问答、关键信息抽取等应用场景。直播时间:8月22日(周四)19:00。报名链接:https://www.wjx.top/vm/Y2f7FFY.aspx?udsid=143844

  • **2024.06.27 PaddleNLP v3.0 Beta**:拥抱大模型,体验全升级。统一大模型套件,实现国产计算芯片全流程接入;全面支持飞桨4D 并行配置、高效精调策略、高效对齐算法、高性能推理等大模型产业级应用流程;自研极致收敛的 RsLoRA+算法、自动扩缩容存储机制 Unified Checkpoint 和通用化支持的 FastFFN、FusedQKV 助力大模型训推;主流模型持续支持更新,提供高效解决方案。

  • **2024.04.24 PaddleNLP v2.8**:自研极致收敛的 RsLoRA+算法,大幅提升 PEFT 训练收敛速度以及训练效果;引入高性能生成加速到 RLHF PPO 算法,打破 PPO 训练中生成速度瓶颈,PPO 训练性能大幅领先。通用化支持 FastFFN、FusedQKV 等多个大模型训练性能优化方式,大模型训练更快、更稳定。

特性

🔧 多硬件训推一体

支持英伟达 GPU、昆仑 XPU、昇腾 NPU、燧原 GCU 和海光 DCU 等多个硬件的大模型和自然语言理解模型训练和推理,套件接口支持硬件快速切换,大幅降低硬件切换研发成本。 当前支持的自然语言理解模型:多硬件自然语言理解模型列表

🚀 高效易用的预训练

支持纯数据并行策略、分组参数切片的数据并行策略、张量模型并行策略和流水线模型并行策略的4D 高性能训练,Trainer 支持分布式策略配置化,降低复杂分布式组合带来的使用成本; Unified Checkpoint 大模型存储格式在模型参数分布上支持动态扩缩容训练,降低硬件切换带来的迁移成本。

🤗 高效精调

精调算法深度结合零填充数据流和 FlashMask 高性能算子,降低训练无效数据填充和计算,大幅提升精调训练吞吐。

🎛️ 无损压缩和高性能推理

大模型套件高性能推理模块内置动态插入和全环节算子融合策略,极大加快并行推理速度。底层实现细节封装化,实现开箱即用的高性能并行推理能力。


模型支持

  • 模型参数已支持 LLaMA 系列、Baichuan 系列、Bloom 系列、ChatGLM 系列、Gemma 系列、Mistral 系列、OPT 系列和 Qwen 系列,详细列表👉【LLM】模型参数支持列表如下:
模型系列模型名称
LLaMAfacebook/llama-7b, facebook/llama-13b, facebook/llama-30b, facebook/llama-65b
LLama2meta-llama/Llama-2-7b, meta-llama/Llama-2-7b-chat, meta-llama/Llama-2-13b, meta-llama/Llama-2-13b-chat, meta-llama/Llama-2-70b, meta-llama/Llama-2-70b-chat
LLama3meta-llama/Meta-Llama-3-8B, meta-llama/Meta-Llama-3-8B-Instruct, meta-llama/Meta-Llama-3-70B, meta-llama/Meta-Llama-3-70B-Instruct
LLama3.1meta-llama/Meta-Llama-3.1-8B, meta-llama/Meta-Llama-3.1-8B-Instruct, meta-llama/Meta-Llama-3.1-70B, meta-llama/Meta-Llama-3.1-70B-Instruct, meta-llama/Meta-Llama-3.1-405B, meta-llama/Meta-Llama-3.1-405B-Instruct, meta-llama/Llama-Guard-3-8B
Baichuanbaichuan-inc/Baichuan-7B, baichuan-inc/Baichuan-13B-Base, baichuan-inc/Baichuan-13B-Chat
Baichuan2baichuan-inc/Baichuan2-7B-Base, baichuan-inc/Baichuan2-7B-Chat, baichuan-inc/Baichuan2-13B-Base, baichuan-inc/Baichuan2-13B-Chat
Bloombigscience/bloom-560m, bigscience/bloom-560m-bf16, bigscience/bloom-1b1, bigscience/bloom-3b, bigscience/bloom-7b1, bigscience/bloomz-560m, bigscience/bloomz-1b1, bigscience/bloomz-3b, bigscience/bloomz-7b1-mt, bigscience/bloomz-7b1-p3, bigscience/bloomz-7b1, bellegroup/belle-7b-2m
ChatGLMTHUDM/chatglm-6b, THUDM/chatglm-6b-v1.1
ChatGLM2THUDM/chatglm2-6b
ChatGLM3THUDM/chatglm3-6b
Gemmagoogle/gemma-7b, google/gemma-7b-it, google/gemma-2b, google/gemma-2b-it
Mistralmistralai/Mistral-7B-Instruct-v0.3, mistralai/Mistral-7B-v0.1
Mixtralmistralai/Mixtral-8x7B-Instruct-v0.1
OPTfacebook/opt-125m, facebook/opt-350m, facebook/opt-1.3b, facebook/opt-2.7b, facebook/opt-6.7b, facebook/opt-13b, facebook/opt-30b, facebook/opt-66b, facebook/opt-iml-1.3b, opt-iml-max-1.3b
Qwenqwen/qwen-7b, qwen/qwen-7b-chat, qwen/qwen-14b, qwen/qwen-14b-chat, qwen/qwen-72b, qwen/qwen-72b-chat,
Qwen1.5Qwen/Qwen1.5-0.5B, Qwen/Qwen1.5-0.5B-Chat, Qwen/Qwen1.5-1.8B, Qwen/Qwen1.5-1.8B-Chat, Qwen/Qwen1.5-4B, Qwen/Qwen1.5-4B-Chat, Qwen/Qwen1.5-7B, Qwen/Qwen1.5-7B-Chat, Qwen/Qwen1.5-14B, Qwen/Qwen1.5-14B-Chat, Qwen/Qwen1.5-32B, Qwen/Qwen1.5-32B-Chat, Qwen/Qwen1.5-72B, Qwen/Qwen1.5-72B-Chat, Qwen/Qwen1.5-110B, Qwen/Qwen1.5-110B-Chat, Qwen/Qwen1.5-MoE-A2.7B, Qwen/Qwen1.5-MoE-A2.7B-Chat
Qwen2Qwen/Qwen2-0.5B, Qwen/Qwen2-0.5B-Instruct, Qwen/Qwen2-1.5B, Qwen/Qwen2-1.5B-Instruct, Qwen/Qwen2-7B, Qwen/Qwen2-7B-Instruct, Qwen/Qwen2-72B, Qwen/Qwen2-72B-Instruct, Qwen/Qwen2-57B-A14B, Qwen/Qwen2-57B-A14B-Instruct
Yuan2IEITYuan/Yuan2-2B, IEITYuan/Yuan2-51B, IEITYuan/Yuan2-102B
  • 4D 并行和算子优化已支持 LLaMA 系列、Baichuan 系列、Bloom 系列、ChatGLM 系列、Gemma 系列、Mistral 系列、OPT 系列和 Qwen 系列,【LLM】模型4D 并行和算子支持列表如下:
模型名称/并行能力支持数据并行张量模型并行参数分片并行流水线并行
基础能力序列并行stage1stage2stage3
Llama✅✅✅✅✅✅✅
Llama2✅✅✅✅✅✅✅
Llama3✅✅✅✅✅✅✅
Llama3.1✅✅✅✅✅✅✅
Qwen✅✅✅✅✅✅✅
Qwen1.5✅✅✅✅✅✅✅
Qwen2✅✅✅✅✅✅✅
Mixtral(moe)✅✅✅✅✅✅🚧
Mistral✅✅🚧✅✅✅🚧
Baichuan(同 llama)✅✅✅✅✅✅✅
Baichuan2✅✅✅✅✅✅✅
ChatGLM✅✅🚧✅✅✅🚧
ChatGLM2✅🚧🚧✅✅✅🚧
ChatGLM3✅🚧🚧✅✅✅🚧
Bloom✅✅🚧✅✅✅🚧
GPT-2/GPT-3✅✅✅✅✅✅✅
OPT✅✅🚧✅✅✅🚧
Gemma✅✅✅✅✅✅✅
Yuan2✅✅✅✅✅✅🚧
  • 大模型预训练、精调(包含 SFT、PEFT 技术)、对齐、量化已支持 LLaMA 系列、Baichuan 系列、Bloom 系列、ChatGLM 系列、Mistral 系列、OPT 系列和 Qwen 系列,【LLM】模型预训练、精调、对齐、量化支持列表如下:
模型名称/能力支持PretrainSFTLoRAPrefix TuningDPORLHFQuantizationTorch convert
LLaMA✅✅✅✅✅✅✅✅
Qwen✅✅✅✅✅🚧🚧✅
Mixtral✅✅✅❌🚧🚧🚧🚧
Mistral✅✅✅✅✅🚧🚧✅
Baichuan/Baichuan2✅✅✅✅✅🚧✅✅
ChatGLM-6B✅✅✅✅🚧🚧✅❌
ChatGLM2/ChatGLM3✅✅✅✅🚧🚧✅✅
Bloom✅✅✅✅🚧🚧✅✅
GPT-3✅✅🚧🚧🚧🚧🚧✅
OPT✅✅✅🚧🚧🚧🚧✅
Yuan2✅✅✅🚧🚧🚧🚧✅

  • 大模型推理已支持 LLaMA 系列、Qwen 系列、Mistral 系列、ChatGLM 系列、Bloom 系列和 Baichuan 系列,支持 Weight Only INT8及 INT4推理,支持 WAC(权重、激活、Cache KV)进行 INT8、FP8量化的推理,【LLM】模型推理支持列表如下:
模型名称/量化类型支持FP16/BF16WINT8WINT4INT8-A8W8FP8-A8W8INT8-A8W8C8
LLaMA✅✅✅✅✅✅
Qwen✅✅✅✅✅✅
Qwen-Moe✅✅✅🚧🚧🚧
Mixtral✅✅✅🚧🚧🚧
ChatGLM✅✅✅🚧🚧🚧
Bloom✅✅✅🚧🚧🚧
BaiChuan✅✅✅✅✅🚧

安装

环境依赖

  • python >= 3.8
  • paddlepaddle >= 3.0.0b0

pip 安装

pip install --upgrade paddlenlp==3.0.0b1

或者可通过以下命令安装最新 develop 分支代码:

pip install --pre --upgrade paddlenlp -f https://www.paddlepaddle.org.cn/whl/paddlenlp.html

更多关于 PaddlePaddle 和 PaddleNLP 安装的详细教程请查看Installation。


快速开始

大模型文本生成

PaddleNLP 提供了方便易用的 Auto API,能够快速的加载模型和 Tokenizer。这里以使用 Qwen/Qwen2-0.5B 模型做文本生成为例:

>>> from paddlenlp.transformers import AutoTokenizer, AutoModelForCausalLM
>>> tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2-0.5B")
>>> model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2-0.5B", dtype="float16")
>>> input_features = tokenizer("你好!请自我介绍一下。", return_tensors="pd")
>>> outputs = model.generate(**input_features, max_length=128)
>>> print(tokenizer.batch_decode(outputs[0], skip_special_tokens=True))
['我是一个AI语言模型,我可以回答各种问题,包括但不限于:天气、新闻、历史、文化、科学、教育、娱乐等。请问您有什么需要了解的吗?']

大模型预训练

git clone https://github.com/PaddlePaddle/PaddleNLP.git && cd PaddleNLP # 如已clone或下载PaddleNLP可跳过
mkdir -p llm/data && cd llm/data
wget https://bj.bcebos.com/paddlenlp/models/transformers/llama/data/llama_openwebtext_100k.bin
wget https://bj.bcebos.com/paddlenlp/models/transformers/llama/data/llama_openwebtext_100k.idx
cd .. # change folder to PaddleNLP/llm
python -u -m paddle.distributed.launch --gpus "0,1,2,3,4,5,6,7" run_pretrain.py ./config/llama/pretrain_argument.json

大模型 SFT 精调

git clone https://github.com/PaddlePaddle/PaddleNLP.git && cd PaddleNLP # 如已clone或下载PaddleNLP可跳过
mkdir -p llm/data && cd llm/data
wget https://bj.bcebos.com/paddlenlp/datasets/examples/AdvertiseGen.tar.gz && tar -zxvf AdvertiseGen.tar.gz
cd .. # change folder to PaddleNLP/llm
python -u -m paddle.distributed.launch --gpus "0,1,2,3,4,5,6,7" run_finetune.py ./config/llama/sft_argument.json

更多大模型全流程步骤,请参考飞桨大模型套件介绍。

更多 PaddleNLP 内容可参考:

  • 精选模型库,包含优质预训练模型的端到端全流程使用。
  • 多场景示例,了解如何使用 PaddleNLP 解决 NLP 多种技术问题,包含基础技术、系统应用与拓展应用。
  • 交互式教程,在🆓免费算力平台 AI Studio 上快速学习 PaddleNLP。

社区交流

  • 微信扫描二维码并填写问卷,即可加入交流群与众多社区开发者以及官方团队深度交流.

Citation

如果 PaddleNLP 对您的研究有帮助,欢迎引用

@misc{=paddlenlp,
    title={PaddleNLP: An Easy-to-use and High Performance NLP Library},
    author={PaddleNLP Contributors},
    howpublished = {\url{https://github.com/PaddlePaddle/PaddleNLP}},
    year={2021}
}

Acknowledge

我们借鉴了 Hugging Face 的Transformers🤗关于预训练模型使用的优秀设计,在此对 Hugging Face 作者及其开源社区表示感谢。

License

PaddleNLP 遵循Apache-2.0开源协议。