2024-02-08 02:19:45 -07:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def fused_kernel_mamba_handle(launcher):
|
|
|
|
with launcher("state-spaces/mamba-130m", num_shard=1) as handle:
|
|
|
|
yield handle
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
async def fused_kernel_mamba(fused_kernel_mamba_handle):
|
|
|
|
await fused_kernel_mamba_handle.health(300)
|
|
|
|
return fused_kernel_mamba_handle.client
|
|
|
|
|
|
|
|
|
2024-06-25 08:53:20 -06:00
|
|
|
@pytest.mark.release
|
2024-02-08 02:19:45 -07:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mamba(fused_kernel_mamba, response_snapshot):
|
|
|
|
response = await fused_kernel_mamba.generate(
|
|
|
|
"What is Deep Learning?", max_new_tokens=10
|
|
|
|
)
|
|
|
|
|
|
|
|
assert response.details.generated_tokens == 10
|
|
|
|
assert response.generated_text == "\n\nDeep learning is a new type of machine"
|
|
|
|
assert response == response_snapshot
|
|
|
|
|
2024-02-08 10:41:25 -07:00
|
|
|
|
2024-06-25 08:53:20 -06:00
|
|
|
@pytest.mark.release
|
2024-02-08 02:19:45 -07:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_mamba_all_params(fused_kernel_mamba, response_snapshot):
|
|
|
|
response = await fused_kernel_mamba.generate(
|
|
|
|
"blue, red, yellow, ",
|
|
|
|
max_new_tokens=10,
|
|
|
|
repetition_penalty=1.2,
|
|
|
|
return_full_text=True,
|
|
|
|
stop_sequences=["test"],
|
|
|
|
temperature=0.5,
|
|
|
|
top_p=0.9,
|
|
|
|
top_k=10,
|
|
|
|
truncate=5,
|
|
|
|
typical_p=0.9,
|
|
|
|
watermark=True,
|
|
|
|
decoder_input_details=True,
|
|
|
|
seed=0,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert response.details.generated_tokens == 10
|
2024-02-08 10:41:25 -07:00
|
|
|
assert (
|
|
|
|
response.generated_text
|
2024-08-15 05:28:42 -06:00
|
|
|
== "blue, red, yellow, \nand blue colors. A number of the color"
|
2024-02-08 10:41:25 -07:00
|
|
|
)
|
2024-02-08 02:19:45 -07:00
|
|
|
assert response == response_snapshot
|
|
|
|
|
2024-02-08 10:41:25 -07:00
|
|
|
|
2024-06-25 08:53:20 -06:00
|
|
|
@pytest.mark.release
|
2024-02-08 02:19:45 -07:00
|
|
|
@pytest.mark.asyncio
|
2024-02-16 03:58:58 -07:00
|
|
|
async def test_mamba_load(
|
|
|
|
fused_kernel_mamba, generate_load, generous_response_snapshot
|
|
|
|
):
|
2024-02-08 10:41:25 -07:00
|
|
|
responses = await generate_load(
|
|
|
|
fused_kernel_mamba, "What is Deep Learning?", max_new_tokens=10, n=4
|
|
|
|
)
|
2024-02-08 02:19:45 -07:00
|
|
|
|
|
|
|
assert len(responses) == 4
|
|
|
|
assert all([r.generated_text == responses[0].generated_text for r in responses])
|
|
|
|
assert responses[0].generated_text == "\n\nDeep learning is a new type of machine"
|
|
|
|
|
Improving mamba runtime by using updates (#1552)
- Move float16 to bfloat16, which has less imprecisions (load test are
failing with the update kernels + f16, all working under bf16).
Another note, is that we are not respecting the layer norm in f32
defined in the configuration (this is OK in my book, but that could
impact the f16 precision)
- Moved to update kernels. Triton overhead is super high, removed by
switching to cuda graphs works great (update cuda graph is available
in TRT-LLM if needed, seems *exactly* like the regular ssm kernel.
- Moved inference_params struct in order to make only 2 tensors, to
reduce the overhead of copying back and forth to the cuda graphs.
- Left over overhead seems entirely in the tokenization bit. (Still 4
copies are paid before launching the graph)
# What does this PR do?
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
2024-02-14 01:54:10 -07:00
|
|
|
assert responses == generous_response_snapshot
|