Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memfix #106

Merged
merged 8 commits into from
Feb 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lighter/callbacks/writer/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any, Callable, Dict, Union

import gc
from abc import ABC, abstractmethod
from datetime import datetime
from pathlib import Path
Expand Down Expand Up @@ -105,7 +106,6 @@ def on_predict_batch_end(
If the IDs are not provided, it generates global unique IDs based on the prediction count.
Finally, it writes the predictions using the specified writer.
"""

# If the IDs are not provided, generate global unique IDs based on the prediction count. DDP supported.
if outputs["id"] is None:
batch_size = len(outputs["pred"])
Expand All @@ -115,3 +115,7 @@ def on_predict_batch_end(

for id, pred in zip(outputs["id"], outputs["pred"]):
self.write(tensor=pred, id=id)

# Clear the predictions to save CPU memory. https://github.com/Lightning-AI/pytorch-lightning/issues/15656
trainer.predict_loop._predictions = [[] for _ in range(trainer.predict_loop.num_dataloaders)]
gc.collect()
Loading