|
| 1 | +# # Initiate the Original Transformer model |
| 2 | +# from QEfficient import QEFFAutoModelForCausalLM as AutoModelForCausalLM |
| 3 | + |
| 4 | +# # Please uncomment and use appropriate Cache Directory for transformers, in case you don't want to use default ~/.cache dir. |
| 5 | +# # os.environ["TRANSFORMERS_CACHE"] = "/local/mnt/workspace/hf_cache" |
| 6 | + |
| 7 | +# # ROOT_DIR = os.path.dirname(os.path.abspath("")) |
| 8 | +# # CACHE_DIR = os.path.join(ROOT_DIR, "tmp") #, you can use a different location for just one model by passing this param as cache_dir in below API. |
| 9 | + |
| 10 | +# # Model-Card name to be onboarded (This is HF Model Card name) : https://huggingface.co/gpt2-xl |
| 11 | +# model_name = "gpt2" # Similar, we can change model name and generate corresponding models, if we have added the support in the lib. |
| 12 | + |
| 13 | +# qeff_model = AutoModelForCausalLM.from_pretrained(pretrained_model_name_or_path="gpt2") |
| 14 | +# print(f"{model_name} optimized for Cloud AI 100 \n", qeff_model) |
| 15 | + |
| 16 | +# # We can now export the modified models to ONNX framework |
| 17 | +# # This will generate single Onnx Model for both Prefill and Decode Variations which are optimized for |
| 18 | +# # Cloud AI 100 Platform. |
| 19 | + |
| 20 | +# # While generating the ONNX model, this will clip the overflow constants to fp16 |
| 21 | +# # Verify the model on Onnxruntime vs Pytorch |
| 22 | + |
| 23 | +# # Then generate inputs and customio yaml file required for compilation. |
| 24 | +# qeff_model.export() |
| 25 | + |
| 26 | +# # Compile the model for provided compilation arguments |
| 27 | +# # Please use platform SDK to Check num_cores for your card. |
| 28 | + |
| 29 | +# qeff_model.compile( |
| 30 | +# num_cores=14, |
| 31 | +# mxfp6=True, |
| 32 | +# device_group=[0], |
| 33 | +# ) |
| 34 | + |
| 35 | +# # post compilation, we can print the latency stats for the kv models, We provide API to print token and Latency stats on Cloud AI 100 |
| 36 | +# # We need the compiled prefill and decode qpc to compute the token generated, This is based on Greedy Sampling Approach |
| 37 | + |
| 38 | +# qeff_model.generate(prompts=["My name is"]) |
| 39 | + |
| 40 | +from transformers import AutoTokenizer |
| 41 | + |
| 42 | +from QEfficient import QEFFAutoModelForCausalLM |
| 43 | + |
| 44 | +print("done") |
| 45 | +model_name = "gpt2" |
| 46 | +# model_name = "google/gemma-3-1b-it" |
| 47 | +# model_name = "meta-llama/Llama-3.1-8B" |
| 48 | +# model_name = "meta-llama/Llama-3.2-1B" |
| 49 | +# model_name = "meta-llama/Llama-3.1-70B" |
| 50 | +# model_name = "meta-llama/Llama-3.1-8B" |
| 51 | +model = QEFFAutoModelForCausalLM.from_pretrained(model_name) |
| 52 | +########################################## |
| 53 | +model.export() |
| 54 | +model.compile(prefill_seq_len=128, ctx_len=256, num_cores=16, num_devices=1) # Qpc file |
| 55 | + |
| 56 | +# model.compile( |
| 57 | +# num_cores=14, |
| 58 | +# mxfp6=True, |
| 59 | +# device_group=[0], |
| 60 | +# ) |
| 61 | +print("done") |
| 62 | +tokenizer = AutoTokenizer.from_pretrained(model_name) |
| 63 | +print("done") |
| 64 | +model.generate(prompts=["Hi there!!"], tokenizer=tokenizer, device_group=[0]) |
| 65 | +print("done") |
| 66 | + |
| 67 | +# from qgenie import ChatMessage, QGenieClient |
| 68 | + |
| 69 | + |
| 70 | +# client = QGenieClient() |
| 71 | + |
| 72 | + |
| 73 | +# chat_response = client.chat( |
| 74 | +# messages=[ |
| 75 | +# ChatMessage(role="user", content="Analyze this repository: https://github.com/quic/efficient-transformers") |
| 76 | +# ], |
| 77 | +# max_tokens=400, |
| 78 | +# ) |
| 79 | + |
| 80 | +# print(chat_response.first_content) |
0 commit comments