gpt4 book ai didi

python - 如何在我的 python 代码中为 Pytorch (IPEX) 启用英特尔扩展?

转载 作者:行者123 更新时间:2023-12-02 01:57:59 25 4
gpt4 key购买 nike

我想在我的代码中使用面向 Pytorch 的英特尔扩展来提高整体性能。引用这个 GitHub( https://github.com/intel/intel-extension-for-pytorch ) 进行安装。

目前,我正在尝试拥抱脸摘要 PyTorch 示例 ( https://github.com/huggingface/transformers/blob/master/examples/pytorch/summarization/run_summarization.py )。以下是用于训练的训练器 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,
)

我不知道在此代码中启用 Ipex。谁能帮我解决这个问题?

提前致谢!

最佳答案

启用 IPEX 所需的关键更改是:

    #Import the library:
import intel_extension_for_pytorch as ipex
#Apply the optimizations to the model for its datatype:
model = ipex.optimize(model)
#torch.channels_last should be applied to both of the model object and data to raise CPU resource usage efficiency.
model = model.to(memory_format=torch.channels_last)
data = data.to(memory_format=torch.channels_last)

此外,请查看 https://intel.github.io/intel-extension-for-pytorch/latest/tutorials/examples.html对于 IPEX 示例。请查看IPEX官网https://www.intel.com/content/www/us/en/developer/tools/oneapi/extension-for-pytorch.html .

关于python - 如何在我的 python 代码中为 Pytorch (IPEX) 启用英特尔扩展?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69404795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com