-
Notifications
You must be signed in to change notification settings - Fork 28
【Hackathon 9th No.100】[Feature Enhancement] add BladeDISC for compiler backend #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thanks for your contribution! |
graph_net/torch/test_compiler.py
Outdated
| } | ||
|
|
||
|
|
||
| class BladeDISCBackend(GraphCompilerBackend): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把基类GraphCompilerBackend 放到单独的 graph_compiler_backend.py 里。
把BladeDISCBackend 实现到 blade_disc_backend.py 里。
| import torch | ||
|
|
||
| try: | ||
| import torch_tensorrt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些代码不应该放到基类里,这不是基类关心的事情
graph_net/torch/test_compiler.py
Outdated
| if cls == InductorBackend: | ||
| return InductorBackend() | ||
| elif cls == TensorRTBackend: | ||
| return TensorRTBackend() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改回去
这些地方原本是工厂模式,结果又变成这种软件质量很差的代码。
| import torch_blade | ||
| except ImportError: | ||
| torch_blade = None | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class BladeDISCCompiledModule(torch.nn.Module):
def __init__(self, module):
super().__init__()
self.module = module
self.counter = 0
def forward(self, *args, **kwargs):
if self.counter == 0:
self.module = self.compile(self.module, *args, **kwargs)
ret = self.module(*args, **kwargs)
self.counter += 1
return ret
def compile(self, module, *args, **kwargs):
dummy_input = tuple([*args, *kwargs.values()])
return torch_blade.optimize(
module, allow_tracing=True, model_inputs=dummy_input
)| def __init__(self, input_dict): | ||
| self.input_dict = input_dict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
去掉
| torch.cuda.synchronize() | ||
|
|
||
|
|
||
| registry_backend = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加回来
|
|
||
| registry_backend = { | ||
| "inductor": InductorBackend(), | ||
| "tensorrt": TensorRTBackend(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
新增"bladedisc: BladeDISCBackend()"
| self.input_dict = input_dict | ||
|
|
||
| def __call__(self, model): | ||
| torch_config = torch_blade.config.Config() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return BladeDISCCompiledModule(model)
graph_net/torch/test_compiler.py
Outdated
| from .graph_compiler_backend import GraphCompilerBackend | ||
| from .inductor_backend import InductorBackend | ||
| from .tensorrt_backend import TensorRTBackend | ||
| from .blade_disc_backend import BladeDISCBackend |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最好直接用绝对路径
|
GraphNet/graph_net/torch/test_compiler.py Line 231 in 5a126f4
|
…e#242) * [Feature Enhancement] add BladeDISC for compiler backend * Fix test_compiler * Fix test_compiler * Fix test_compiler and blade_disc_backend * update bladedisc version info
PR Category
Feature Enhancement
Description
为
graph_net.torch.test_compiler支持后端使用 BladeDISC 编译器,即支持配置--compiler "bladedisc",读取GraphNet/samples目录下的子图,可成功执行并获得正确的评测结果。以 Bert 为例 Optimize and Inference BERT with TorchBlade,主要执行流程为:
torch.jit.trace或torch.jit.script把 PyTorch 模型转成 TorchScripttorch_blade.optimize进行编译优化,生成编译后的 compiled_modelcompiled_model (input)以执行前向其中,结合
torch.jit.trace或torch.jit.script进行编译优化的过程可以简单抽象为:在本次集成中使用的是
torch.jit.trace; 使用官方镜像bladedisc/bladedisc:latest-runtime-torch1.12.0-cu113以快速获取编译器性能测评数据。详细技术报告请参考BladeDISC_tech_report.md测试报告:
import torch_blade)在(2025.08.30)现有/samples中没有出现一整类都无法运行的情况。/samples/cosyvoice下全部的模型,在GPU A100-SXM-40GB 上批量性能测试可见BladeDISC_batch_test.txt。/samples每个类别测试一种模型,测试报告可见BladeDISC_validation_report.txt,性能速览如下: