xrsrke / pipegoose

Large scale 4D parallelism pre-training for 🤗 transformers in Mixture of Experts *(still work in progress)*
MIT License
80 stars 18 forks source link

Kernel Fusion using torch.jit #10

Open xrsrke opened 1 year ago

xrsrke commented 1 year ago

Fuse some popular functions and automatically replace modules in an existing 🤗 transformers model with their corresponding fusion module

APIs

from pipegoose.nn import fusion

# and other parallelism ...
model = TensorParallel(model, parallel_context).parallelize()
model.fuse()

# or selective kernel fusion
model.fuse([fusion.LayerNorm, fusion.Attention])

TODOs

Reading (could be ignored)

sami-bg commented 1 year ago

Can you assign this to me? I'd like to give this a shot

sami-bg commented 1 year ago

https://github.com/xrsrke/pipegoose/pull/36

xrsrke commented 1 year ago

@sami-bg Check out torch.fx. We could use it to detect modules in a transformers model that can be fused and replace them with the fused version: model.transformers.blocks[0].dropout = fused_dropout

But we don't do it manually. Check out this tutorial for how to use torch.fx: https://pytorch.org/tutorials/intermediate/fx_conv_bn_fuser.html