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

[Model] Jamba support #4115

Open
wants to merge 103 commits into
base: main
Choose a base branch
from
Open

[Model] Jamba support #4115

wants to merge 103 commits into from

Conversation

mzusman
Copy link
Contributor

@mzusman mzusman commented Apr 16, 2024

Add Jamba support to vLLM,
This PR comprises three parts:

  1. The Jamba modeling file that encapsulates the Jamba model weights and logic itself and the mamba cache management.
  2. Passage of the requests ids of the sequence groups and their sequence ids into the modeling file in order to be able to manage the cache.
  3. Passage of the finished request ids into the modeling file as well in order the clean the allocated cache on finished requests

ErezSC42 and others added 28 commits April 16, 2024 10:13
BA-78554: Jurassic 2.5

* worked on jurasic2.5 configuration file, updated jurassic2_5 modeling file to support alternating experts/attn layers

* finished working the forward pass of jurassic3.py

* finished working the forward pass of jurassic3.py

* finished working the forward pass of jurassic3.py

* jurassic_3 modeling file works, uses dummy weights initialized by "dummy" flag. Tokenizer raises issues, for now copying the mixtral tokenizer

* changed default tokenizer vocab values, loading of custom .pt weight files works.

* removed notebook

* merging master to jurassic-2.5 to reset head

* Merge branch 'master' into jurassic-2.5

* align to master

Approved-by: Tomer Asida
Approved-by: Mor Zusman
BA-78760: Jamba

* Add support for n concat and splitting

* change naming

* input_metadata is a dict list now in order to pass "n"

* clean up code from unecessary changes and prints

* Remove kv cache allocation in case of mamba layer

* Add the considerations of mamba layer cache into the num of blocks
calculation

* Delete mamba cache after profile

* Remove prints

* Cleaning

* - and not _ for requirements

Approved-by: Tomer Asida
* Remove assertion

* adapting jamba vllm to changes after hf release, working on weight loading in modeling file

* splitting the JambaDecoderLayer to JambaMambaDecoderLayer and JambaAttentionDecoderLayer

* weight loading from hf checkpoint supposedly works, might be a mixup in the MoE between the gated and non-gated weights

* Add mamba from jamba modeling file

* Remove slow forward

* Modifications to mamba_mixer

* Save changes, WIP

* Fix cache placement

* Debugging

* Additions and logging

* Jamba with mamba cache handling

* Clean up

* Another cleanup

* Use vllm's RMSNorm instead of JambaRMSNorm, Thier implementation is with
fused kernel

* Clean up and orginization of the objects to handle the mamba cache

* Shorten the code for kv cache mem

* Move cache handling inside the Mixer

* Add mamba to the wheel requirements

* Add mamba to the requirements script

* Add mamba_metadata

* Add to __init__ __all__

* Revert 2 commits

ad1a3db 'Add mamba to the requirements script'
75ed2c8 'Add mamba to the wheel requirements'

* Clean up

* Naming

* Apply whitespace suggestions from code review

* pass tie_word_embeddings to PretrainedConfig init

* Replace repeat with expand as expand doesn't require more mem

* Allocate really small cache if needed , don't use meta

* Fix for expanded

---------

Co-authored-by: Mor Zusman <[email protected]>
Co-authored-by: Erez Schwartz <[email protected]>
Co-authored-by: tomeras91 <[email protected]>
* Drop indecies when finish

* min 1 attention layer

* CG is working on forward pass passing

* Remove comments

* cosmetics - rename indecies -> indices, organize some whitespaces

* Add some TODOs

* Adding mamba cache for cg

* Remove useless vars from input_metadata

* Remove unused import

* Set the seqlen offset to boolean

* Return only hidden state

* Return only hidden states

* Add padding to match forward pass bs

* Is prompt instead of seqlen offset

* Remove mamba cache class (not used)

* Another remove

* Remove

* Use mamba4gc

* Fix mamba forward, run update only on non prompt

* Use 1 index after the maximal index

* Remove import

* Remove import

* typo

* typo

* place holder

* Padding and empty token takes it from the first empty place

* reformat

* Apply suggestions from code review

Whitespaces

---------

Co-authored-by: Mor Zusman <[email protected]>
Co-authored-by: Tomer Asida <[email protected]>
Co-authored-by: tomeras91 <[email protected]>
Co-authored-by: Mor Zusman <[email protected]>
* Return support for other models apart from jamba

* Support n>1

* A little cleanup

* Rename

* Apply whitespace suggestions from code review

* Add max batch size to the main func

* Fixed attention kv cache bug

* log where requests id are deleted from the dict to debug mode

* Fix typo

* Align with v0.3.3 vllm code

* Remove comments

* Take out model config from CUDAGraph object

* Fix

* Fix typo

* Make the kv cache selection cleaner

* Another typo

* Took the num layers calc outside

* Remove the -1

* Set as num layer / period

---------

Co-authored-by: Mor Zusman <[email protected]>
Co-authored-by: tomeras91 <[email protected]>
* Return support for other models apart from jamba

* Support n>1

* Revert 2 commits

d054737 'Support n>1'
b5167cc 'Return support for other models apart from jamba'

* TP on input and output

* Basic TP impl , working, correctness not working

* TP is working

* Roll back the verification that everything in the weights fits into the
model

* Cleanup

* Use world size func

* clean up

* Import

* Apply whitespace suggestions from code review

* Organize imports

* Add comment on the unsqueeze in conv1d

* Organize and remove redundant code in forward pass

* Remove print

* Add comments

Co-authored-by: tomeras91 <[email protected]>

* White spaces

* Set as A

* better comment

---------

Co-authored-by: Mor Zusman <[email protected]>
Co-authored-by: tomeras91 <[email protected]>
@robertgshaw2-neuralmagic
Copy link
Collaborator

Cool!

vllm/config.py Show resolved Hide resolved
vllm/core/scheduler.py Outdated Show resolved Hide resolved
vllm/core/scheduler.py Outdated Show resolved Hide resolved
vllm/model_executor/models/__init__.py Show resolved Hide resolved
vllm/core/scheduler.py Outdated Show resolved Hide resolved
vllm/worker/cache_engine.py Show resolved Hide resolved
vllm/worker/model_runner_base.py Outdated Show resolved Hide resolved
vllm/worker/cpu_model_runner.py Show resolved Hide resolved
vllm/worker/embedding_model_runner.py Outdated Show resolved Hide resolved
vllm/worker/model_runner.py Show resolved Hide resolved
@mzusman mzusman marked this pull request as ready for review June 27, 2024 14:06
tests/models/test_jamba.py Show resolved Hide resolved
vllm/worker/cache_engine.py Outdated Show resolved Hide resolved
vllm/core/scheduler.py Outdated Show resolved Hide resolved
vllm/model_executor/models/jamba.py Outdated Show resolved Hide resolved
@mzusman
Copy link
Contributor Author

mzusman commented Jun 30, 2024

AFAIU CI distributed-tests-2-gpus test fails regardless of this PR.

Copy link
Collaborator

@cadedaniel cadedaniel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks good to me. I will push to get it merged (we also want to use the new finished_request_ids bookkeeping in #5765 (comment)).

One edge-case that is missed is in the scheduler, where a certain lineage of a sequence can cause it to be finished without ever notifying the Worker. I would rather get this merged and fix that in another PR given it's so esoteric.

I left some nits; feel free to fix impactful ones now or in a follow up PR. Want to get this merged to avoid more rebase work.

I will get another reviewer for the requirements-mamba and Dockerfile. Other parts LGTM.

vllm/config.py Show resolved Hide resolved
vllm/core/scheduler.py Outdated Show resolved Hide resolved
vllm/core/scheduler.py Outdated Show resolved Hide resolved
vllm/worker/model_runner.py Show resolved Hide resolved
vllm/core/scheduler.py Outdated Show resolved Hide resolved
vllm/model_executor/models/jamba.py Show resolved Hide resolved
@WoosukKwon
Copy link
Collaborator

QQ: Does this PR support parallel sampling (i.e., n > 1 in sampling params)? While I don't think it is not necessary to support parallel sampling in this PR, I'd like to know if this case was considered. Supporting parallel sampling might be a bit hard since it requires implementing copy_blocks for the Mamba cache. If this is not trivial, please leave a comment on the code.

@mzusman
Copy link
Contributor Author

mzusman commented Jul 1, 2024

QQ: Does this PR support parallel sampling (i.e., n > 1 in sampling params)? While I don't think it is not necessary to support parallel sampling in this PR, I'd like to know if this case was considered. Supporting parallel sampling might be a bit hard since it requires implementing copy_blocks for the Mamba cache. If this is not trivial, please leave a comment on the code.

This PR does support parallel sampling, We transfer the seq_ids along with the requests_ids into the Jamba inner state mapping and copy the blocks accordingly, reference in the Jamba code

Copy link
Contributor

@tlrmchlsmth tlrmchlsmth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks good to me as well.

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.

None yet

9 participants