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

Fix memory leak from sigint signal and deepspeed #2

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 9 additions & 5 deletions src/axolotl/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
configure_logging()
LOG = get_logger("axolotl.train")


@dataclass
class TrainDatasetMeta:
"""
Expand Down Expand Up @@ -139,10 +138,10 @@ def terminate_handler(_, __, model_weakref):
sys.exit(0)

_model_weakref = weakref.ref(model)
signal.signal(
signal.SIGINT,
lambda signum, frame: terminate_handler(signum, frame, _model_weakref),
)
# signal.signal(
# signal.SIGINT,
# lambda signum, frame: terminate_handler(signum, frame, _model_weakref),
# )

badge_markdown = """[<img src="https://raw.githubusercontent.com/OpenAccess-AI-Collective/axolotl/main/image/axolotl-badge-web.png" alt="Built with Axolotl" width="200" height="32"/>](https://github.com/OpenAccess-AI-Collective/axolotl)"""
transformers.modelcard.AUTOGENERATED_TRAINER_COMMENT += f"\n{badge_markdown}"
Expand Down Expand Up @@ -234,6 +233,11 @@ def terminate_handler(_, __, model_weakref):
# defensively push to the hub to ensure the model card is updated
trainer.push_to_hub()

if cfg.deepspeed:
trainer.deepspeed.destroy()
trainer.accelerator.free_memory()
trainer.model, trainer.model_wrapped, trainer.optimizer = None, None, None

return model, tokenizer


Expand Down