简体   繁体   English

如何在我的 python 代码中启用 Intel Extension for Pytorch(IPEX)?

[英]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.

相关问题 如何为我的独立可启动代码启用 SSE? - How do I enable SSE for my freestanding bootable code? 对于证书,如何从 Google CA 启用对“CanSignHttpExchanges”扩展的支持? - For certificate, how to enable support for "CanSignHttpExchanges" extension from Google CA? 如何加速我的 python 代码与 DB 一起工作? - How to speed up my python code working with DB? 如何在 Google Cloud 上正确启用 extension=imagick.so - How proper enable extension=imagick.so on Google Cloud 在使用 Node.js 连接到 S3 时,如何让我在 AWS Fargate 容器中运行的代码承担 IAM 角色? - How do I enable my code runing in a AWS Fargate container to assume an IAM role when connecting to S3 with Node.js? 如何仅启用对我的 nativescript 应用程序的 firestore 数据访问? - How to enable access of firestore data to my nativescript app only? 如何在批处理脚本中启动 Intel Power Gadget? - How to start Intel Power Gadget in Batch Script? 如何修复 stream_socket_enable_crypto():SSL 操作失败,代码为 1 - how to fix stream_socket_enable_crypto(): SSL operation failed with code 1 如何在英特尔 RAPL 焦点设备上获取功率读数? - How to get power reading on an Intel RAPL focal appliance? 如何在我的云设备库实例上启用 SAP GUI 脚本? - How do I enable SAP GUI scripting on my Cloud Appliance Library Instance?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM