Skip to content

Add coreml eager model compare #11574

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
15 changes: 13 additions & 2 deletions examples/apple/coreml/llama/llama_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class ModelArgs:
use_scaled_rope: bool = True # Use scaled RoPE, introduced in llama3.1.
# Additional Model Metadata needed at runtime
rope_scale_factor: int = 8
high_freq_factor: int = 4

bos_idx: int = 1
eos_idx: int = 3
bos_count: int = -1 # i.e., a single EOS is used as BOS
Expand All @@ -74,6 +76,9 @@ class ModelArgs:

use_cache_list: bool = True

use_kv_cache: bool = False
enable_dynamic_shape: bool = False

def __post_init__(self):
if self.n_kv_heads is None:
self.n_kv_heads = self.n_heads
Expand Down Expand Up @@ -160,10 +165,16 @@ def __init__(self, params: ModelArgs):
super().__init__()
self.params = params
if self.params.use_hf_rope:
self.precompute_freqs_cis = hf_precompute_freqs_cis
self.precompute_freqs_cis = partial(
hf_precompute_freqs_cis,
partial_rotary_factor=self.params.partial_rotary_factor,
)
else:
self.precompute_freqs_cis = partial(
precompute_freqs_cis, use_scaled=self.params.use_scaled_rope
precompute_freqs_cis,
use_scaled=self.params.use_scaled_rope,
scale_factor=self.params.rope_scale_factor,
high_freq_factor=self.params.high_freq_factor,
)
freqs_cos, freqs_sin = self.precompute_freqs_cis(
self.params.head_dim,
Expand Down
Loading