Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion build/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def _initialize_model(
device_sync(device=builder_args.device)

try:
from build.model_et import PTEModel
from build.model import PTEModel

model = PTEModel(model.config, builder_args.pte_path)
except Exception:
Expand Down
33 changes: 33 additions & 0 deletions build/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,36 @@ def apply_rotary_emb(x: Tensor, freqs_cis: Tensor) -> Tensor:

x_out2 = x_out2.flatten(3)
return x_out2.type_as(x)


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ExecuTorch model components
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

try:
from executorch.extension.pybindings import portable_lib as exec_lib

# ET changed the way it's loading the custom ops so it's not included in portable_lib but has to be loaded separately.
from executorch.examples.models.llama2.custom_ops import sdpa_with_kv_cache # no-qa

class PTEModel(nn.Module):
def __init__(self, config, path) -> None:
super().__init__()
self.config = config
self.model_ = exec_lib._load_for_executorch(str(path))

def forward(self, x, input_pos):
# model_.forward expects inputs to be wrapped in a tuple
forward_inputs = (x.to(torch.long), input_pos.to(torch.long))
logits = self.model_.forward(forward_inputs)

# After wrapping in a tuple, we get a list back, so we need to grab
# the first element to get the tensor
assert len(logits) == 1
logits = logits[0]
return logits

def setup_caches(self, max_batch_size, max_seq_length):
pass
except:
pass
32 changes: 0 additions & 32 deletions build/model_et.py

This file was deleted.