def apply_compilation(model, optimizer): model.encoder.encoder.layer = torch.nn.ModuleList( [torch.compile(layer, fullgraph=True) for layer in model.encoder.encoder.layer] ) model.decoder.transformer.h = torch.nn.ModuleList( [torch.compile(layer, fullgraph=True) for layer in model.decoder.transformer.h] ) model.loss_function = torch.compile(model.loss_function, fullgraph=True) optimizer.step = torch.compile(optimizer.step) return model, optimizer