aimhubio / aim

Aim 💫 — An easy-to-use & supercharged open-source experiment tracker.
https://aimstack.io
Apache License 2.0
4.93k stars 298 forks source link

AimLogger not working with PyTorch lightning #3088

Open gursi26 opened 5 months ago

gursi26 commented 5 months ago

❓Question

Here is my code for the PyTorch lightning trainer

import lightning as L

trainer = L.Trainer(
    max_epochs=EPOCHS,
    accelerator=DEVICE,
    logger = aim.Run(experiment="trial_exp_lightning")
)
trainer.fit(training_module, train_loader, test_loader)

Upon running this, I get the following error message.

AttributeError: 'Run' object has no attribute 'save_dir'

I have checked previous issues in both the lightning and aim repos and it seems that integration is possible, so im wondering how I should go about fixing this.

tamohannes commented 5 months ago

Hey @gursi26, Aim provides a built-in callback manager specifically designed for PyTorch Lightning. It is highly recommended to utilize this manager to handle all PyTorch Lightning events effectively.

Here's how your code snippet will appear after making those changes:

import lightning as L

aim_logger = AimLogger(
    experiment_name="trial_exp_lightning",
)

trainer = L.Trainer(
    max_epochs=EPOCHS,
    accelerator=DEVICE,
    logger = aim_logger
)
trainer.fit(training_module, train_loader, test_loader)

You can refer for more details on this page: https://aimstack.readthedocs.io/en/latest/quick_start/integrations.html#integration-with-pytorch-lightning

Feel free to share any additional issues you may encounter ☺️