Skip to content

[Refactor] Added a new spec for PagedKVCache #17837

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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion python/tvm/relax/frontend/nn/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""Compilation specifications, for example, dynamic shape inputs."""
import inspect
import typing
from .llm.kv_cache import PagedKVCache as _PagedKVCache

if typing.TYPE_CHECKING:
from .core import Module as nn_module_class
Expand Down Expand Up @@ -64,6 +65,14 @@ def __repr__(self) -> str:
return "object"


class PagedKVCache(Object): # pylint: disable=too-few-public-methods
"""A specialized spec that extends Object for a paged key-value cache."""

def __init__(self) -> None:
# Pass the type of this class to the Object constructor.
super().__init__(object_type=_PagedKVCache)


Comment on lines +68 to +75
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @annanyapr, we will need PagedKVCache to be its own standalone class here, rather than a subclass of Object. This will also need us to support the kv cache StructInfo first. I think a better order is to work on the StructInfo and runtime checking (with unit tests) first, and then come back to work on the nn frontend spec.

class Tuple: # pylint: disable=too-few-public-methods
"""A tuple input or a list input"""

Expand Down Expand Up @@ -92,7 +101,7 @@ class MethodSpec:
param_mode: str # "plain", "packed", "none"
effect_mode: str # "plain", "packed", "none"

def __init__( # pylint: disable=too-many-arguments
def __init__( # pylint: disable=too-many-positional-arguments,too-many-arguments
self,
method: typing.Callable,
arg_names: typing.List[str],
Expand Down