-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exporting and numerics verification for CLIP Large text model wit…
…h IREE (#664) Add exporting to MLIR and IRRE parameters. We don't make the context length dynamic since the maximum is only 77 anyway, so the token sequences are padded to 77. We could explore later making this dynamic. This adds comparison of IREE execution of float32, bfloat16 model variants against float32 torch eager. For bfloat16 results are close up to 1.43e-2 using cosine similarity. Toy-sized model comparison for float32 and bfloat16 is also provided.
- Loading branch information
Showing
8 changed files
with
482 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2024 Advanced Micro Devices, Inc. | ||
# | ||
# Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
from ...layers.configs.llm_configs import ClipTextConfig | ||
from ...types.theta import Theta | ||
from .export import hugging_face_clip_text_model_to_theta | ||
import torch | ||
|
||
|
||
def make_clip_text_model_random_theta(config: ClipTextConfig) -> Theta: | ||
from transformers import CLIPTextConfig as HfCLIPTextConfig | ||
from transformers import CLIPTextModel as HfCLIPTextModel | ||
|
||
hf_config = config.to_hugging_face_clip_text_model_config() | ||
model = HfCLIPTextModel(hf_config) | ||
return hugging_face_clip_text_model_to_theta(model) | ||
|
||
|
||
def make_random_input_token_sequences( | ||
batch_size: int, config: ClipTextConfig | ||
) -> torch.LongTensor: | ||
sequence_lens = torch.randint( | ||
low=1, high=config.max_position_embeddings + 1, size=(batch_size,) | ||
) | ||
sequences = torch.full( | ||
size=(batch_size, config.max_position_embeddings), | ||
fill_value=config.eos_token_id, | ||
dtype=torch.long, | ||
) | ||
for batch_idx, l in enumerate(sequence_lens): | ||
sequences[batch_idx][0:l] = torch.randint( | ||
low=0, high=config.vocab_size - 1, size=(l,), dtype=torch.long | ||
) | ||
return sequences |
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
Oops, something went wrong.