【Hackathon 9th No.98】[Feature Enhancement] Add Xla Backend for test_compile #248
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Category
Feature Enhancement
Description
为 graph_net.torch.test_compiler支持后端使用Xla编译器
需要配置 --compiler "xla",同时需要设置环境变量PJRT_DEVICE来指定cuda或者cpu(不设置的话自动检测,优先使用cuda)
测试版本 torch_xla - 2.7 (CUDA 12.6 + Python 3.11)whl包,torch_xla 的版本和torch的版本是一一对应的(CUDA版本也是需要对应的,官方编译的现在大部分都是CPU的),在最新版本的xla中,已经移除了对CUDA的支持,只支持TPU,CPU后端
对模型中创建张量时硬编码的设备处理上,使用抽象语法树来替代字符串提取替换,同时新增device参数
对于xla编译器,需要把所有张量都创建在xla设备上,xla仅支持转化到cpu上
对比速度的时候,前向运行在cuda上,编译过的模型运行在xla(实际设备为cuda)上