-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
[Model] Allow loading from original Mistral format #8168
New issue
Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “No 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? No Sign in to your account
[Model] Allow loading from original Mistral format #8168
Conversation
👋 Hi! Thank you for contributing to the vLLM project. Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can do one of these:
🚀 |
/ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is reasonable overall but are these consolidated checkpoints going to be actively used going forward?
We tend to want to conform to HF as a standard, so if these checkpoints don't load in transformers now then I think the community will continue to have interest in having those be converted to canonical "HF-style" checkpoints
cache_dir: Optional[str], | ||
index_file: str, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nit: I think it makes more sense to have cache_dir after index_file, similar to how hf_hub_download is called
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
happy to change
@@ -104,6 +110,56 @@ def get_config( | |||
return config | |||
|
|||
|
|||
def load_params_config(model, revision) -> PretrainedConfig: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why you have this new config? It seems to have the same information you would have in the config.json, just named differently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main reason is because the original format is always stored in params.json which accompanies the consolidated.safetensors checkpoints.
Guess there are two problems with config.json
-
- They are tied quite heavily to transformers. So if one wants to add a new, no transformers-formatted model it doesn't make too much sense to follow transformers config style
-
- They tend to be quite bloated, e.g. has info that's outdated such as
sliding_window
here: https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.3/blob/e0bc86c23ce5aae1db576c8cca6f06f1f73af2db/config.json#L19
- They tend to be quite bloated, e.g. has info that's outdated such as
vllm/model_executor/models/llama.py
Outdated
# Mistral/Llama models can also be loaded with --load-format consolidated | ||
# from consolidated.safetensors checkpoints | ||
consolidated_mapping = { | ||
"layers": "model.layers", | ||
"attention": "self_attn", | ||
"wq": "q_proj", | ||
"wk": "k_proj", | ||
"wv": "v_proj", | ||
"wo": "o_proj", | ||
"attention_norm": "input_layernorm", | ||
"feed_forward": "mlp", | ||
"w1": "gate_proj", | ||
"w2": "down_proj", | ||
"w3": "up_proj", | ||
"ffn_norm": "post_attention_layernorm", | ||
"tok_embeddings": "model.embed_tokens", | ||
"output": "lm_head", | ||
"norm": "model.norm" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a standard naming scheme used by Llama models as well? I have only seen Mistral models with these style of checkpoints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the original LLama checkpoints have this naming as well: https://github.com/meta-llama/llama/blob/8fac8befd776bc03242fe7bc2236cdb41b6c609c/llama/model.py#L207
(guess most people use the HF format indeed though)
Hey @mgoin, Yes at Mistral we usually only release the consolidated checkpoints to begin with (see table here). The community then usually converts the models to transformers but this takes some time and then it takes even more time to wait for the next transformers release. So yes, I think the consolidated format will surely continued to be used! I understand that it's easier to just conform to HF-style, but I guess VLLM also has GGUF support and it could make sense to start allowing more and more support for other formats? Guess in the future VLLM can run any nn.Module regardless of whether it's in transformers or not no? The biggest reason why I think it makes sense to allow also for the consolidated format is so that users could have day-0 inference support for Mistral models for future model releases. VLLM is essentially implementing all the model architectures natively in the model register, so it's just about "correctly" loading the file format no? It's a bit painful to have to adapt mistral format to transformers format to allow inference in VLLM. With mistral-common in VLLM and with consolidated.safetensors format loading, models like Mistral-Nemo should be supported out of the box on day 0. Happy to adapt the PR in a way that fits the design better! |
vllm/config.py
Outdated
@@ -744,6 +747,7 @@ class LoadFormat(str, enum.Enum): | |||
SHARDED_STATE = "sharded_state" | |||
GGUF = "gguf" | |||
BITSANDBYTES = "bitsandbytes" | |||
CONSOLIDATED = "consolidated" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CONSOLIDATED is a bit broad as a name no ? Especially since there is SHARDED_STATE above, I think it could lead to confusion.
Thoughts on LoadFormat.MISTRAL ? This makes it clear that the intent is to have us support / maintain the integration of our models into vLLM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes makes sense!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on calling it "MISTRAL" format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, it's better to be explicit if possible
Thanks for the feedback @timlacroix @mgoin - think everything should be incorporated. Let me know if there is anything else that should be changed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate your explanation and justification @patrickvonplaten ! I think this is in a good place, my last gripe is with load_params_config
since it would be good to future-proof this for other load formats in the future that may require similar changes. Look in the comments for my proposal
tests/models/test_mistral.py
Outdated
# test that both HF format and mistral format work | ||
load_format = "mistral" if model.endswith("v0.3") else "auto" | ||
|
||
with vllm_runner(model, | ||
dtype=dtype, | ||
tokenizer_mode="mistral", | ||
load_format=load_format) as vllm_model: | ||
vllm_outputs = vllm_model.generate_greedy_logprobs( | ||
example_prompts, max_tokens, num_logprobs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be best if you specifically made a test for "mistralai/Mistral-7B-Instruct-v0.3" where you test the model load with both "safetensors" and "mistral" (and HF to just ensure reference) since both checkpoint formats are present on that model card.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense! Thanks - will take care of it in a bit
vllm/config.py
Outdated
load_params_config: Load the config from mistral format | ||
(params.json) instead of config.json. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you made some good points on supporting checkpoint formats other than HF. Given that assumption, I think it would be best to future-proof the interface of config overrides.
I would like to propose changing this parameter to something like config_format
that takes a value from a ConfigFormat
enum, defaulting to ConfigFormat.HF_CONFIG or AUTO. Then get_config()
can dispatch based on this value to the specified config parsing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes a lot of sense!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on getting the CI green, looks like you're close. It does seem like AUTO is causing trouble here, so I would be okay with removing it and defaulting to HF if you can't get it stable. Otherwise this LGTM so we can land when green
Yeah I think it should be fine now (CI is all green). GGUF tests were failing because they didn't default to HF. Fixed it and everything should work fine now I believe! Thanks for guiding me through the PR! |
Co-authored-by: Michael Goin <michael@neuralmagic.com>
will this work for pixtral as well? |
Co-authored-by: Michael Goin <michael@neuralmagic.com> Signed-off-by: Alvant <alvasian@yandex.ru>
Co-authored-by: Michael Goin <michael@neuralmagic.com> Signed-off-by: Amit Garg <mitgarg17495@gmail.com>
Will this work for the Llama original formats, which, e.g., are in the formats of |
Hi all, I just pulled the latest Docker version and am still getting this error when running Pixtral-12B-2409. Was this fix ever released or am I doing something incorrectly? |
Co-authored-by: Michael Goin <michael@neuralmagic.com> Signed-off-by: LeiWang1999 <leiwang1999@outlook.com>
Mistral models are usually uploaded in two formats:
The original consolidated format:
consolidated.safetensors
params.json
A bit later the HF format is usually also uploaded:
model-00001-of-00003.safetensors
config.json
This PR allows to load directly from the original consolidated format which should make it easier to directly get new models working in VLLM.
The PR can be tested with:
or:
BEFORE SUBMITTING, PLEASE READ THE CHECKLIST BELOW AND FILL IN THE DESCRIPTION ABOVE
PR Checklist (Click to Expand)
Thank you for your contribution to vLLM! Before submitting the pull request, please ensure the PR meets the following criteria. This helps vLLM maintain the code quality and improve the efficiency of the review process.
PR Title and Classification
Only specific types of PRs will be reviewed. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:
[Bugfix]
for bug fixes.[CI/Build]
for build or continuous integration improvements.[Doc]
for documentation fixes and improvements.[Model]
for adding a new model or improving an existing model. Model name should appear in the title.[Frontend]
For changes on the vLLM frontend (e.g., OpenAI API server,LLM
class, etc.)[Kernel]
for changes affecting CUDA kernels or other compute kernels.[Core]
for changes in the core vLLM logic (e.g.,LLMEngine
,AsyncLLMEngine
,Scheduler
, etc.)[Hardware][Vendor]
for hardware-specific changes. Vendor name should appear in the prefix (e.g.,[Hardware][AMD]
).[Misc]
for PRs that do not fit the above categories. Please use this sparingly.Note: If the PR spans more than one category, please include all relevant prefixes.
Code Quality
The PR need to meet the following code quality standards:
format.sh
to format your code.docs/source/
if the PR modifies the user-facing behaviors of vLLM. It helps vLLM user understand and utilize the new features or changes.Notes for Large Changes
Please keep the changes as concise as possible. For major architectural changes (>500 LOC excluding kernel/data/config/test), we would expect a GitHub issue (RFC) discussing the technical design and justification. Otherwise, we will tag it with
rfc-required
and might not go through the PR.What to Expect for the Reviews
The goal of the vLLM team is to be a transparent reviewing machine. We would like to make the review process transparent and efficient and make sure no contributor feel confused or frustrated. However, the vLLM team is small, so we need to prioritize some PRs over others. Here is what you can expect from the review process:
action-required
label on the PR if there are changes required. The contributor should address the comments and ping the reviewer to re-review the PR.Thank You
Finally, thank you for taking the time to read these guidelines and for your interest in contributing to vLLM. Your contributions make vLLM a great tool for everyone!