GithubHelp home page GithubHelp logo

Comments (2)

aakashvardhan avatar aakashvardhan commented on July 30, 2024

I think you can call the trainer class property 'logged_metrics', which calls the train loss

for example:

# Retrieve logged losses
    train_losses = trainer.logged_metrics['train_loss']
    
    # Check if the final loss is lower than the initial loss
    initial_loss = train_losses[0]
    final_loss = train_losses[-1]
    
    assert final_loss < initial_loss,

from lightning.

svnv-svsv-jm avatar svnv-svsv-jm commented on July 30, 2024

Not really. logged_metrics only holds the last value:

print(logged_metrics)
>>> {'train_loss': tensor(0.0162), 'train_loss_step': tensor(0.0162), 'train_loss_epoch': tensor(0.0162)}

So I had to do something like:

# Run a fake training just to get the loss over one batch at the start (`max_steps=1`)
    trainer = Trainer(
        logger=False,
        enable_checkpointing=False,
        accelerator="auto",
        overfit_batches=1,
        max_steps=1,
    )
    trainer.fit(model, loader)
    logged_metrics = trainer.callback_metrics
    logger.info(logged_metrics)
    loss_before = logged_metrics["train_loss"]

    # Now overfit on the same batch, but for more steps and get the loss
    trainer = Trainer(
        logger=False,
        enable_checkpointing=False,
        accelerator="auto",
        overfit_batches=1,
        **kwargs,
    )
    trainer.fit(model, loader)
    logged_metrics = trainer.callback_metrics
    logger.info(logged_metrics)
    loss_after = logged_metrics["train_loss"]

which is not nice.

Either an example of how this is intended to be done should be provided, or handle specially the case when overfit_batches>0.

from lightning.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.