Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
script for phi3 (#1541)
Browse files Browse the repository at this point in the history
Co-authored-by: zhenwei-intel <zhenwei.liu@intel.com>
  • Loading branch information
airMeng and zhenwei-intel authored May 11, 2024
1 parent fd37c8d commit 2af19c7
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from intel_extension_for_transformers.transformers import AutoModelForCausalLM, AutoRoundConfig, RtnConfig, GPTQConfig
from intel_extension_for_transformers.transformers.llm.quantization.utils import convert_dtype_str2torch
from transformers.utils import check_min_version
import contextlib

parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down Expand Up @@ -241,8 +242,10 @@
generate_kwargs = dict(do_sample=False, temperature=0.9, num_beams=args.num_beams)
if args.profile_token_latency:
ipex.transformers.optimize.convert_function(user_model, "greedy_search", _greedy_search)
ipex.transformers.optimize.convert_function(user_model, "_greedy_search", _greedy_search)
if args.disable_optimize_transformers:
ipex.transformers.optimize.convert_function(user_model, "beam_search", _beam_search)
ipex.transformers.optimize.convert_function(user_model, "_beam_search", _beam_search)
user_model.config.token_latency = True

total_time = 0.0
Expand All @@ -253,7 +256,11 @@
dtype=amp_dtype if amp_enabled else None,
):
for i in range(num_iter + num_warmup):
with torch.autograd.profiler_legacy.profile(enabled=args.do_profiling, use_xpu=(args.device=="xpu"), record_shapes=False) as prof:
if args.do_profiling:
context = torch.autograd.profiler_legacy.profile(enabled=args.do_profiling, use_xpu=True, record_shapes=True)
else:
context = contextlib.nullcontext()
with context as prof:
input_ids = tokenizer(
prompt, return_tensors="pt").input_ids.to(args.device)
tic = time.time()
Expand Down

0 comments on commit 2af19c7

Please sign in to comment.