Repository navigation
Disable compilation for training_step, validation_step, etc. #21569
Replies: 1 comment 3 replies
|
_LIGHTNING_MODULE_STEP_METHODS = ("training_step", "validation_step", "test_step", "predict_step")is seeded straight into
Two ways out Compile only forward before fabric.setup model.forward = torch.compile(model.forward)
model, optimizer = fabric.setup(model, optimizer)
Or keep compiling the wrapped module but stop Fabric from reapplying it fabric.setup(model, optimizer, _reapply_compile=False)documented for exactly this case compiling the DDP or FSDP wrapped module without Fabric refusing it |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi! I am training a model with Fabric and would like to compile only the
forwardmethod of the model and skip compilation for thetraining_step,validation_step, etc. The reason for this is thattraining_stepcontains hard to compile logic like metrics tracking and has dynamic inputs.forwardhowever is safe to compile.It seems that the forward wrapping magic in Fabric automatically results in
training_stepto be compiled as well and I haven't managed to excludetraining_stepfrom compilation. I tried wrapping it in@torch.compiler.disable()but that didn't work. Callingmodel.training_step = torch.compiler.disable(model.training_step, recursive=False)doesn't work if called beforefabric.setupand results in a recursion depth exceeded error if called afterfabric.setup.Any hints on how to achieve this or what the best practice is for this scenario?
Code to reproduce:
Output:
Here the compile limit is reached because
filenameis different in every training step.What does work is calling torch.compile only on the forward:
But then
fabric.setupdoesn't re-apply compilation because not the whole model was compiled. This is at least my understanding.All reactions