Skip to content
Closed
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
8 changes: 4 additions & 4 deletions extension/export_util/export_hf_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner
from executorch.exir import EdgeCompileConfig, ExecutorchBackendConfig, to_edge
from torch.nn.attention import SDPBackend
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers import AutoModelForCausalLM
from transformers.generation.configuration_utils import GenerationConfig
from transformers.integrations.executorch import convert_and_export_with_cache
from transformers.modeling_utils import PreTrainedModel
Expand Down Expand Up @@ -73,12 +73,11 @@ def main() -> None:
print(f"{model.config}")
print(f"{model.generation_config}")

tokenizer = AutoTokenizer.from_pretrained(args.hf_model_repo)
input_ids = tokenizer([""], return_tensors="pt").to(device)["input_ids"]
input_ids = torch.tensor([[1]], dtype=torch.long)
cache_position = torch.tensor([0], dtype=torch.long)

def _get_constant_methods(model: PreTrainedModel):
return {
metadata = {
"get_dtype": 5 if model.config.torch_dtype == torch.float16 else 6,
"get_bos_id": model.config.bos_token_id,
"get_eos_id": model.config.eos_token_id,
Comment on lines 82 to 83
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@larryliu0820 Is it safe to leave it unset and let the runtime to use the default value? Or it's preferred to set it to some special value e.g. -1, if any of the field is unset by a model?

Expand All @@ -90,6 +89,7 @@ def _get_constant_methods(model: PreTrainedModel):
"get_vocab_size": model.config.vocab_size,
"use_kv_cache": model.generation_config.use_cache,
}
return {k: v for k, v in metadata.items() if v is not None}

with torch.nn.attention.sdpa_kernel([SDPBackend.MATH]), torch.no_grad():

Expand Down
Loading