Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW Model] Add mamba #8513

Merged
merged 18 commits into from
Aug 19, 2024
Merged

[NEW Model] Add mamba #8513

merged 18 commits into from
Aug 19, 2024

Conversation

JunnYu
Copy link
Member

@JunnYu JunnYu commented May 30, 2024

PR types

New features

PR changes

Models

Description

Mamba: Linear-Time Sequence Modeling with Selective State Spaces
作者仓库
huggingface仓库

需要develop版本的paddlepaddle
如何使用:
1.(可选)编译自定义cuda算子,https://github.com/JunnYu/mamba/tree/paddle-v2.2.2
2. 运行下面的代码。

import paddle
from paddlenlp.transformers import MambaForCausalLM, MambaTokenizer
from paddlenlp.generation import GenerationConfig

name = "state-spaces/mamba-2.8b-hf"

tokenizer = MambaTokenizer.from_pretrained(name)
model = MambaForCausalLM.from_pretrained(name, dtype="float16", low_cpu_mem_usage=True)
model.eval()

generation_config = GenerationConfig(
    decode_strategy="sampling",
    top_k=50,
    num_return_sequences=4,
    use_cache=True,
)

with paddle.no_grad():
    prompt = "Hello, it is"
    inputs = tokenizer.encode(prompt, return_tensors="pd")
    outputs = model.generate(**inputs, generation_config=generation_config, max_length=256)
    for e in tokenizer.batch_decode(outputs[0], skip_special_tokens=True):
        print(prompt + e)
        print('-'*100)

Copy link

paddle-bot bot commented May 30, 2024

Thanks for your contribution!

@JunnYu
Copy link
Member Author

JunnYu commented Jul 25, 2024

更新

Copy link

codecov bot commented Aug 16, 2024

Codecov Report

Attention: Patch coverage is 85.42056% with 78 lines in your changes missing coverage. Please review.

Project coverage is 55.00%. Comparing base (e0d2809) to head (1244675).
Report is 225 commits behind head on develop.

Files with missing lines Patch % Lines
paddlenlp/transformers/mamba/modeling.py 79.87% 65 Missing ⚠️
paddlenlp/transformers/mamba/tokenizer.py 92.35% 13 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8513      +/-   ##
===========================================
+ Coverage    54.79%   55.00%   +0.20%     
===========================================
  Files          636      640       +4     
  Lines        99876   100543     +667     
===========================================
+ Hits         54732    55307     +575     
- Misses       45144    45236      +92     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

DrownFish19
DrownFish19 previously approved these changes Aug 16, 2024
@JunnYu JunnYu merged commit b08e445 into PaddlePaddle:develop Aug 19, 2024
10 of 12 checks passed
Mangodadada pushed a commit to Mangodadada/PaddleNLP that referenced this pull request Sep 10, 2024
* add mamba

* update

* do not shift

* update

* push

* mamba 单测pass

* mamba

* update_model_kwargs_for_generation

* fix tests

* test

* test

* add tokenizer test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants