-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix executorch kv cache incompatibility with to_executorch lowering (#…
- Loading branch information
Showing
8 changed files
with
365 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,32 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
|
||
from typing import List | ||
|
||
from executorch.exir.pass_base import ExportPass | ||
|
||
|
||
class InitializedMutableBufferPass(ExportPass): | ||
""" | ||
If a buffer has a name that within a specified list, set meta["et_init_buffer"] | ||
to True, which provides the mutable buffer with an initialized state. | ||
As an example, a module with `self.register_buffer("cache_pos", torch.arange(10))` | ||
when patterns = ["cache_pos"] would have its initial state set instead of being | ||
left uninitialized by default. | ||
""" | ||
|
||
def __init__(self, patterns: List[str]) -> None: | ||
super().__init__() | ||
self.patterns = patterns | ||
|
||
def placeholder(self, name: str, arg, meta): | ||
for pattern in self.patterns: | ||
if pattern in name: | ||
meta["et_init_buffer"] = True | ||
|
||
return super().placeholder(name, arg, meta) |
This file contains 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 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.