Comments (2)
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.
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)
- Please allow automatic optimization for multiple optimizers again. HOT 2
- Sometimes error when logging model graph with `functional.interpolate` and `deterministic=True`
- Adding support for Python 12? HOT 2
- Pytorch FSDPStrategy saving checkpoint behavior work correctly?
- pl.TrainResult not found in 2.3.3 HOT 1
- LightningCLI doesn't save optimizer's configuration if not explicitly given HOT 4
- Get `num_nodes` automatically HOT 2
- What happens during training with HuggingFace models in eval mode? HOT 2
- OptimizerLRScheduler typing does not fit examples HOT 3
- TypeError: on_train_batch_start() takes 3 positional arguments but 4 were given HOT 3
- CSV Logger acts weirdly in Callbacks
- Error when disabling an optimizer with native AMP turned on HOT 1
- Have an example of showing explicitly how to calculate metrics in DDP for lightning 2.2.0
- Wrong hparams when using lightning cli HOT 3
- Attribute error on `_NotYetLoadedTensor` loading checkpoint into quantized model HOT 1
- Why does the progress bar not show the total steps when using iterable dataset? HOT 2
- training=False when use a pretrained model like BERT HOT 3
- Documentation for filename convention of save_top_k in ModelCheckpoint HOT 6
- Email Callback on training done
- what is the difference between DDP and single-GPU for profiler? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lightning.