-
Couldn't load subscription status.
- Fork 45
feat: Adds a vllm backend #122
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
Open
guicho271828
wants to merge
27
commits into
generative-computing:main
Choose a base branch
from
guicho271828:masa/vllm-backend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
a8ec184
feat: added smaller qwen models for debugging
guicho271828 dbfd4aa
feat(vllm): copied from huggingface
guicho271828 c2445aa
fix(vllm): remove alora and cache
guicho271828 c4b06ff
fix(vllm): remove tool calls
guicho271828 0a081c9
fix(vllm): finished the implementation with limited functionality: fr…
guicho271828 29ea548
fix(vllm): passing mypy and linter
guicho271828 5808d95
fix(vllm): added vllm optional dep in pyproject.toml
guicho271828 872c529
feat(vllm test): copied from huggingface
guicho271828 12df402
fix(vllm test): implemented the test
guicho271828 015c62b
test: require V0 in vllm test
guicho271828 003e766
refactor: ctx to chat conversion function
guicho271828 9a5f557
refactor: use_alora function
guicho271828 f586128
refactor: moved _extract_model_tool_requests to mellea.backends.utils
guicho271828 3571098
feat(vllm): added tool calls
guicho271828 cd339c7
test(tools): run test with mistral
guicho271828 e8a69f0
fix(vllm): rename model_options -> engine_args
guicho271828 a3ee501
fix(vllm): use FancyLogger
guicho271828 d25579a
fix(vllm): ignore type checking for vllm and msgspec
guicho271828 fd1b3a4
fix(vllm): fixed the backend name in the log
guicho271828 2a12031
feat(vllm): asynchronous call support
guicho271828 356dfd5
test(vllm): asynchronous call support
guicho271828 39ad431
fix(vllm): avoid unnecessary incremental processing in non-streaming …
guicho271828 7452a1f
fix(vllm): fix for the new return format
guicho271828 9daa4e2
fix(vllm): fixed vllm test for the new contexts
55397ad
fix(vllm): addressed minor comments
guicho271828 32db5eb
fix(vllm): uv lock
guicho271828 9709103
fix(vllm): mark V0 api test qualitative; will be removed in a future …
guicho271828 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import inspect | ||
| from collections.abc import Callable | ||
| from typing import Any, Literal | ||
|
|
||
| from mellea.backends.aloras import Alora | ||
| from mellea.backends.formatter import Formatter | ||
| from mellea.backends.tools import parse_tools | ||
| from mellea.helpers.fancy_logger import FancyLogger | ||
| from mellea.stdlib.base import CBlock, Component, Context, ModelToolCall | ||
| from mellea.stdlib.chat import Message | ||
| from mellea.stdlib.requirement import ALoraRequirement, LLMaJRequirement, Requirement | ||
|
|
||
| # Chat = dict[Literal["role", "content"], str] # external apply_chat_template type hint is weaker | ||
| # Chat = dict[str, str | list[dict[str, Any]] ] # for multi-modal models | ||
| Chat = dict[str, str] | ||
|
|
||
|
|
||
| def to_chat( | ||
| action: Component | CBlock, | ||
| ctx: Context, | ||
| formatter: Formatter, | ||
| system_prompt: str | None, | ||
| ) -> list[Chat]: | ||
| """Converts a context and an action into a series of dicts to be passed to apply_chat_template . | ||
|
|
||
| This function is used by local inference backends. | ||
| """ | ||
| assert ctx.is_chat_context | ||
|
|
||
| linearized_ctx = ctx.view_for_generation() | ||
| assert linearized_ctx is not None, ( | ||
| "If ctx.is_chat_context, then the context should be linearizable." | ||
| ) | ||
| ctx_as_message_list: list[Message] = formatter.to_chat_messages(linearized_ctx) | ||
| # add action | ||
| ctx_as_message_list.extend(formatter.to_chat_messages([action])) | ||
|
|
||
| ctx_as_conversation: list = [ | ||
| {"role": m.role, "content": m.content} for m in ctx_as_message_list | ||
| ] | ||
|
|
||
| # Check that we ddin't accidentally end up with CBlocks. | ||
| for msg in ctx_as_conversation: | ||
| for v in msg.values(): | ||
| if "CBlock" in v: | ||
| FancyLogger.get_logger().error( | ||
| f"Found the string `CBlock` in what should've been a stringified context: {ctx_as_conversation}" | ||
| ) | ||
|
|
||
| # handle custom system prompts. It's important that we do this before the _parse_and_**clean**_model_options step. | ||
| if system_prompt is not None: | ||
| system_msg: Chat = {"role": "system", "content": system_prompt} | ||
| ctx_as_conversation.insert(0, system_msg) | ||
|
|
||
| return ctx_as_conversation | ||
|
|
||
|
|
||
| def use_alora( | ||
| action: Component | CBlock, | ||
| alora: Alora | None, | ||
| default_to_constraint_checking_alora: bool, | ||
| ) -> bool: | ||
| """Returns True when the condition for using alora is met. | ||
|
|
||
| See `docs/dev/requirement_aLoRA_rerouting.md` for an explanation of the following code block. | ||
| """ | ||
| if issubclass(type(action), Requirement): | ||
| # The general rule is that we reroute to the alora if it exists. | ||
| reroute_to_alora = alora is not None | ||
| # However, there are some exceptions: | ||
| if not default_to_constraint_checking_alora: | ||
| reroute_to_alora = False | ||
| if issubclass(type(action), LLMaJRequirement): | ||
| reroute_to_alora = False | ||
| if issubclass(type(action), ALoraRequirement): | ||
| reroute_to_alora = True | ||
| return reroute_to_alora | ||
| else: | ||
| return False | ||
|
|
||
|
|
||
| def to_tool_calls( | ||
| tools: dict[str, Callable], decoded_result: str | ||
| ) -> dict[str, ModelToolCall] | None: | ||
| """Parse a tool call string.""" | ||
| model_tool_calls: dict[str, ModelToolCall] = dict() | ||
| for tool_name, tool_args in parse_tools(decoded_result): | ||
| func = tools.get(tool_name) | ||
| if func is None: | ||
| FancyLogger.get_logger().warning( | ||
| f"model attempted to call a non-existing function: {tool_name}" | ||
| ) | ||
| continue | ||
|
|
||
| # Clean up the function args slightly. Some models seem to | ||
| # hallucinate parameters when none are required. | ||
| sig = inspect.signature(func) | ||
| if len(sig.parameters) == 0: | ||
| tool_args = {} | ||
|
|
||
| model_tool_calls[tool_name] = ModelToolCall(tool_name, func, tool_args) | ||
|
|
||
| if len(model_tool_calls) > 0: | ||
| return model_tool_calls | ||
| return None | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.