NVIDIA / TransformerEngine

A library for accelerating Transformer models on NVIDIA GPUs, including using 8-bit floating point (FP8) precision on Hopper and Ada GPUs, to provide better performance with lower memory utilization in both training and inference.
https://docs.nvidia.com/deeplearning/transformer-engine/user-guide/index.html
Apache License 2.0
1.61k stars 256 forks source link

Do not attempt importing submodules if framework is not available #844

Closed timmoon10 closed 1 month ago

timmoon10 commented 1 month ago

Description

https://github.com/NVIDIA/TransformerEngine/pull/839 breaks Lightning Thunder's JIT infrastructure (see https://github.com/NVIDIA/TransformerEngine/pull/839#issuecomment-2108824717). Thunder calls inspect.stack, which indiscriminately interacts with all of Transformer Engine's submodules, including lazily loaded submodules for JAX and PaddlePaddle that are intended to throw import errors.

This is a quick fix that only attempts to import submodules if the corresponding DL framework is available. The original bug may reemerge if a Thunder user incidentally has JAX or PaddlePaddle in their Python environment.

Type of change

Changes

Checklist: