Skip to content

[Core] generate from input embeds - #6869

Closed
Nan2018 wants to merge 126 commits into
vllm-project:mainfrom
protopia-ai:feature-input-embeds
Closed

Nan2018 wants to merge 126 commits into
vllm-project:mainfrom
protopia-ai:feature-input-embeds

Conversation

@Nan2018

@Nan2018 Nan2018 commented Jul 27, 2024 •

Copy link
Copy Markdown
Contributor

adds support for passing prompt_embeds to LLM.generate as

llm.generate({"prompt_embeds": input_embeds}, sampling_params)

or

llm.generate(
    [{"prompt_embeds": input_embeds} for input_embeds in inputs_embeds], sampling_params
)

this enables use cases when only the embedding layer is finetuned, and have the same model backend support multiple custom tuned embedding layers

FIX #416
FIX #8323

inspired by #1265 which is very outdated

@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the vLLM project.
Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which consists a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of default ones by unblocking the steps in your fast-check build on Buildkite UI.

Once the PR is approved and ready to go, please make sure to run full CI as it is required to merge (or just use auto-merge).

To run full CI, you can do one of these:

  • Comment /ready on the PR
  • Add ready label to the PR
  • Enable auto-merge.

🚀

@Nan2018

Nan2018 commented Aug 8, 2024 •

Copy link
Copy Markdown
Contributor Author

@WoosukKwon @ywang96 @robertgshaw2-neuralmagic

the failed tests with
ValueError: Cannot use apply_chat_template() because tokenizer.chat_template is not set and no template argument was passed! For information about writing templates and setting the tokenizer.chat_template attribute, please see the documentation at https://huggingface.co/docs/transformers/main/en/chat_templating
seems not related to my changes and I can't reproduce it locally.

other than that, this is ready for review

@ywang96

ywang96 commented Aug 8, 2024

Copy link
Copy Markdown
Member

@WoosukKwon @ywang96 @robertgshaw2-neuralmagic

the failed tests with ValueError: Cannot use apply_chat_template() because tokenizer.chat_template is not set and no template argument was passed! For information about writing templates and setting the tokenizer.chat_template attribute, please see the documentation at https://huggingface.co/docs/transformers/main/en/chat_templating seems not related to my changes and I can't reproduce it locally.

other than that, this is ready for review

This is due to a recent change from transformers of deprecating default chat template, and it should have been fixed by #7238. Can you merge your branch with main again?

@Nan2018
Nan2018 force-pushed the feature-input-embeds branch from 3f79009 to dfd9301 Compare September 4, 2024 22:27
@CandiedCode

Copy link
Copy Markdown

@DarkLight1337 since #10374 has landed, is this pr going to be updated so that this work can be finished, or is there a new PR you can reference for tracking?

@DarkLight1337

DarkLight1337 commented Dec 19, 2024 •

Copy link
Copy Markdown
Member

@DarkLight1337 since #10374 has landed, is this pr going to be updated so that this work can be finished, or is there a new PR you can reference for tracking?

Thanks for your interest. At the moment, V1 isn't stable enough to implement embedding inputs yet. I would point you to #8779 to check the progress, but that RFC is somewhat outdated. Instead, you can search for recent PRs with the [V1] tag.

@CandiedCode

CandiedCode commented Dec 19, 2024 •

Copy link
Copy Markdown

Thanks for your interest. At the moment, V1 isn't stable enough to implement embedding inputs yet. I would point you to #8779 to check the progress, but that RFC is somewhat outdated. Instead, you can search for recent PRs with the [V1] tag.

Thanks for the reference, @DarkLight1337 . Is it possible also to add this to the roadmap for additional visibility as well?

@ywang96

ywang96 commented Dec 19, 2024 •

Copy link
Copy Markdown
Member

Thanks for your interest. At the moment, V1 isn't stable enough to implement embedding inputs yet. I would point you to #8779 to check the progress, but that RFC is somewhat outdated. Instead, you can search for recent PRs with the [V1] tag.

Thanks for the reference, @DarkLight1337 . Is it possible also to add this to the roadmap for additional visibility as well?

Hey @CandiedCode! Thanks for following up on this.

IMO supporting embeddings as input as is does not have technical difficulty but we do want to be careful with the design to make it work with all other features we want to natively support on vLLM, especially now that we're going through re-architecture. I have discussed briefly with @WoosukKwon in #11032 (comment) about it.

In particular, some issues we still need to design and address:

  • What happens if a batch has both token ids as input and embeddings as input?
  • Prefix caching (Currently we use token ids as hash key)
  • Spec decode (we assume draft models to output token id to be accepted by main model)

@HaiFengZeng

Copy link
Copy Markdown

using the code for inference,prompt_embeds.size= torch.Size([85, 896])

for tk in llm.generate({'prompt_embeds':prompt_input},sample_params):
    print(tk)

and it raise Exception as below:

rank0]: Traceback (most recent call last):
[rank0]:   File "/AIOT-vePFS/speech/workspace/zenghaifeng/sllm/CosyVoice2-0.5B/vllm-test.py", line 17, in <module>
[rank0]:     for tk in llm.generate({'prompt_embeds':prompt_input},sample_params):
[rank0]:   File "/root/miniconda3/lib/python3.10/site-packages/vllm/utils.py", line 1063, in inner
[rank0]:     return fn(*args, **kwargs)
[rank0]:   File "/root/miniconda3/lib/python3.10/site-packages/vllm/entrypoints/llm.py", line 396, in generate
[rank0]:     outputs = self._run_engine(use_tqdm=use_tqdm)
[rank0]:   File "/root/miniconda3/lib/python3.10/site-packages/vllm/entrypoints/llm.py", line 931, in _run_engine
[rank0]:     step_outputs = self.llm_engine.step()
[rank0]:   File "/root/miniconda3/lib/python3.10/site-packages/vllm/engine/llm_engine.py", line 1415, in step
[rank0]:     ) = self.scheduler[virtual_engine].schedule()
[rank0]:   File "/root/miniconda3/lib/python3.10/site-packages/vllm/core/scheduler.py", line 1219, in schedule
[rank0]:     scheduler_outputs: SchedulerOutputs = self._schedule()
[rank0]:   File "/root/miniconda3/lib/python3.10/site-packages/vllm/core/scheduler.py", line 1178, in _schedule
[rank0]:     return self._schedule_default()
[rank0]:   File "/root/miniconda3/lib/python3.10/site-packages/vllm/core/scheduler.py", line 1013, in _schedule_default
[rank0]:     prefills = self._schedule_prefills(budget,
[rank0]:   File "/root/miniconda3/lib/python3.10/site-packages/vllm/core/scheduler.py", line 885, in _schedule_prefills
[rank0]:     num_new_tokens = self._get_num_new_tokens(seq_group,
[rank0]:   File "/root/miniconda3/lib/python3.10/site-packages/vllm/core/scheduler.py", line 1605, in _get_num_new_tokens
[rank0]:     assert num_new_tokens > 0
[rank0]: AssertionError

how to solve this?

@DarkLight1337

Copy link
Copy Markdown
Member

I think the latest working commit is 49fe3f7

Please revert to the above commit. The current vLLM is not compatible with input embeds yet.

@serser

serser commented Jan 2, 2025

Copy link
Copy Markdown

It seems the length of a sequence of prompt_embeds is always 0 due to get_len which keeps the scheduler has nothing to schedule, hence deadlocking here. Am I right?

@DarkLight1337

Copy link
Copy Markdown
Member

It seems the length of a sequence of prompt_embeds is always 0 due to get_len which keeps the scheduler has nothing to schedule, hence deadlocking here. Am I right?

Yeah, that is the problem.

@solume

solume commented Feb 5, 2025

Copy link
Copy Markdown

is there a version of this that currently works for input_embed + prompt for text-only model?

@DarkLight1337

Copy link
Copy Markdown
Member

is there a version of this that currently works for input_embed + prompt for text-only model?

No, can you elaborate on the use case of mixing these two? vLLM already does prefix caching so this shouldn't be necessary.

@solume

solume commented Feb 5, 2025

Copy link
Copy Markdown

I'm using an embedding that comes externally as context that I need to prepend to the text. So I have a context vector the size of the hidden dimension of the LLM, and a prompt text. I have a patched vllm where I pass down an input_embeds array to the model (I'm using llama.py), and then I'm adding the prefix in the forward pass like this:


    def forward(
        ...
        inputs_embeds: Optional[torch.Tensor] = None,
    ) -> Union[torch.Tensor, IntermediateTensors]:
        ...
        if inputs_embeds is not None and input_ids is not None:
            text_embeds = self.get_input_embeddings(input_ids)
            inputs_embeds = torch.cat([inputs_embeds, text_embeds], dim=1)
            input_ids = None
        elif inputs_embeds is None:
            inputs_embeds = self.get_input_embeddings(input_ids)
            input_ids = None

        model_output = self.model(
            input_ids,
            positions,
            kv_caches,
            attn_metadata,
            intermediate_tensors,
            inputs_embeds,
        )

so was wondering if there is a way of doing this without such a patch.

@DarkLight1337

DarkLight1337 commented Feb 6, 2025 •

Copy link
Copy Markdown
Member

I think you can use prompt adapter request (#4645) for the prepended embeddings. It's going to be deprecated in V1 though.

I suggest that you simply pass the context alongside the prompt in each request. There should be little overhead for doing so when prefix caching is enabled.

@CandiedCode

CandiedCode commented Feb 10, 2025 •

Copy link
Copy Markdown

Hi @ywang96 and @DarkLight1337

Last time you guys mentioned that following still needed to be designed and address:

What happens if a batch has both token ids as input and embeddings as input?
Prefix caching (Currently we use token ids as hash key)
Spec decode (we assume draft models to output token id to be accepted by main model)

I wanted to check to see if there had been any progress made on these efforts.

Thanks for all that you guys do!

~CandiedCode

@DarkLight1337

Copy link
Copy Markdown
Member

Hi @ywang96 and @DarkLight1337

Last time you guys mentioned that following still needed to be designed and address:

What happens if a batch has both token ids as input and embeddings as input?
Prefix caching (Currently we use token ids as hash key)
Spec decode (we assume draft models to output token id to be accepted by main model)

I wanted to check to see if there had been any progress made on these efforts.

Thanks for all that you guys do!

~CandiedCode

To avoid complicating the development of V1, we haven't really touched this yet. We'll consider this once it is more stable.

@amuvarma13

Copy link
Copy Markdown

Any progress on this?

@mergify mergify Bot added tpu Related to Google TPUs and removed tpu Related to Google TPUs labels Mar 27, 2025
qthequartermasterman added a commit to qthequartermasterman/vllm that referenced this pull request Apr 2, 2025
Co-authored-by: Nan2018 <nan@protopia.ai>
Signed-off-by: Andrew Sansom <andrew@protopia.ai>
@mergify mergify Bot added the tpu Related to Google TPUs label Apr 9, 2025
@mergify mergify Bot removed the tpu Related to Google TPUs label Apr 11, 2025
@DarkLight1337

Copy link
Copy Markdown
Member

Closing in favor of #15428

@tongjin0521

tongjin0521 commented Jul 22, 2025 •

Copy link
Copy Markdown

Hi @ywang96 and @DarkLight1337
This is currently only supported in v0 engine, which is going to be deprecated.
Also, for example, v0 doesn't support flex attention, any plan on generating from input embeds in v1 engine?
Or is there a quick fix to achieve this?

@qthequartermasterman

Copy link
Copy Markdown
Contributor

Hi @ywang96 and @DarkLight1337

This is currently only supported in v0 engine, which is going to be deprecated.

Also, for example, v0 doesn't support flex attention, any plan on generating from input embeds in v1 engine?

Or is there a quick fix to achieve this?

@Nan2018 and I are writing up an RFC for v1 support. We're hoping to open it this week. We'll have a draft PR in the next few weeks.

wenhow pushed a commit to wenhow/vllm that referenced this pull request Aug 5, 2026
### What this PR does / why we need it?
Added Yuanrong as a new KV Pool storage backend for
`AscendStoreConnector`.

openYuanrong dataSystem is a memory-centric, near-compute distributed
heterogeneous multi-level cache system. It provides high-performance
data object and data stream access, HBM/DRAM/SSD multi-tier caching, and
zero-copy data sharing between instances for distributed applications
such as AI training and inference, agents, big data, and microservices.
> For additional context on openYuanrong datasystem, please refer to:
https://atomgit.com/openeuler/yuanrong-datasystem

### Does this PR introduce _any_ user-facing change?
Yes. Users can now configure `AscendStoreConnector` to use the Yuanrong
backend by setting `"backend": "yuanrong"` in the
`kv_connector_extra_config`. This requires installing the
`openyuanrong-datasystem` package and configuring environment variables
such as `DS_WORKER_ADDR`.

### How was this patch tested?
The new Yuanrong backend was tested in a mixed deployment scenario to
ensure its functionality. The setup and inference commands used for
testing are now part of the updated documentation in
`docs/source/user_guide/feature_guide/kv_pool.md`, allowing for easy
reproduction of the test environment.

- vLLM version: v0.18.0
- vLLM main:
vllm-project@ed359c4

Signed-off-by: yangsonglin13 <yangsonglin566@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do vLLM support input_embeds as input while using LLama? [Feature Request] Support input embedding in LLM.generate()