[英]How to enable Intel Extension for Pytorch(IPEX) in my python code?
I would like to use Intel Extension for Pytorch in my code to increase overall performance.我想在我的代码中使用 Intel Extension for Pytorch 来提高整体性能。 Referred this GitHub( https://github.com/intel/intel-extension-for-pytorch ) for installation.
参考此 GitHub ( https://github.com/intel/intel-extension-for-pytorch ) 进行安装。
Currently, I am trying out a hugging face summarization PyTorch sample( https://github.com/huggingface/transformers/blob/master/examples/pytorch/summarization/run_summarization.py ).目前,我正在尝试一个拥抱脸摘要 PyTorch 示例( https://github.com/huggingface/transformers/blob/master/examples/pytorch/summarization/run_summarization.py )。 Below is the trainer API used for training.
下面是用于训练的训练器 API。
# Initialize our Trainer trainer = Seq2SeqTrainer( model=model, args=training_args, train_dataset=train_dataset if training_args.do_train else None, eval_dataset=eval_dataset if training_args.do_eval else None, tokenizer=tokenizer, data_collator=data_collator, compute_metrics=compute_metrics if training_args.predict_with_generate else None, )
I am not aware of enabling Ipex in this code.我不知道在此代码中启用 Ipex。 Can anyone help me with this?
谁能帮我这个?
Thanks in Advance!提前致谢!
For enabling Intel Extension for Pytorch you just have to give add this to your code,要启用 Pytorch 的英特尔扩展,您只需将其添加到您的代码中,
import intel_extension_for_pytorch as ipex
Importing above extends PyTorch with optimizations for extra performance boost on Intel hardware上面的导入扩展了 PyTorch,优化了英特尔硬件的额外性能提升
After that you have to add this in your code之后,您必须在代码中添加它
model = model.to(ipex.DEVICE)
First, you will need to subclass the Trainer object and create an custom optimizer as described in the Hugging Face docs首先,您需要继承 Trainer 对象并创建自定义优化器,如Hugging Face 文档中所述
The APIs for using intel_extension_for_pytorch
has changed a bit, to use the library, you just have to do:使用
intel_extension_for_pytorch
的 API 发生了一些变化,要使用该库,您只需:
import intel_extension_for_prytorch as ipex
model, optimizer = ipex.optimize(model, optimizer=optimizer)
Currently, Transformers 4.21 has support IPEX.目前,变形金刚 4.21 已经支持 IPEX。 IPEX Graph Optimization with JIT-mode
使用 JIT 模式的 IPEX 图优化
python run_qa.py
--model_name_or_path csarron/bert-base-uncased-squad-v1 \
--dataset_name squad \
--do_eval \
--max_seq_length 384 \
--doc_stride 128 \
--output_dir /tmp/ \
--no_cuda \
--use_ipex \
--jit_mode_eval
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.