-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[eplatero] Add support for exporting and compiling models for SpD
(https://jira-dc.qualcomm.com/jira/browse/CLOUDPERF-43) This change has been validated and posted on behalf of Erick Platero. It adds support for generating a Target LM to run as a verifier model by outputting all logits instead of just that of the last position for the input sequence. It also allows compiling the Target and Draft LMs with specializations that support SpD Usage: TLM: tlm = QEFFAutoModelForCausalLM.from_pretrained(<tlm-model-card>) tlm.transform(num_speculative_tokens=<k>) tlm.export_and_compile(<compiler-args>) DLM: dlm = QEFFAutoModelForCausalLM.from_pretrained(<dlm-model-card>) dlm.transform(is_dlm=True) dlm.export_and_compile(<compiler-args>)
- Loading branch information
Apoorva Gokhale
committed
Sep 23, 2024
1 parent
afb4645
commit dbc1712
Showing
6 changed files
with
88 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from typing import Optional | ||
|
||
import torch | ||
|
||
|
||
def filter_hidden_states( | ||
hidden_states: torch.Tensor, | ||
position_ids: torch.Tensor, | ||
num_speculative_tokens: Optional[int], | ||
) -> torch.Tensor: | ||
"""filter hidden states based on whether this is a TLM SpD model""" | ||
batch_indices = torch.arange(position_ids.shape[0]) | ||
if num_speculative_tokens is not None: | ||
# all logits need to be computed | ||
return hidden_states[batch_indices].squeeze(1) | ||
# Cast to INT32 to avoid issue while running in ONNXRT | ||
logit_index = position_ids.to(torch.int32).argmax(1, keepdim=True) | ||
return hidden_states[batch_indices.view(-1, 1), logit_index] |
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