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

Raise errors from run_training #151

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
34 changes: 13 additions & 21 deletions src/instructlab/training/main_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,28 +663,20 @@ def run_training(torch_args: TorchrunArgs, train_args: TrainingArgs) -> None:
command.append("--cpu_offload_optimizer_pin_memory")

print(f"\033[92mRunning command: {' '.join(command)}\033[0m")
process = None
process = StreamablePopen(
f"{train_args.ckpt_output_dir}/full_logs_global{torch_args.node_rank}.log",
command,
)
print("\033[91mTerminating process 🤖\033[0m")
process.terminate()
try:
process = StreamablePopen(
f"{train_args.ckpt_output_dir}/full_logs_global{torch_args.node_rank}.log",
command,
)

except KeyboardInterrupt:
print("Process interrupted by user")
except Exception as e:
print(f"An error occurred: {str(e)}")
finally:
if "process" not in locals() or process is None:
return

print("\033[91mTerminating process 🤖\033[0m")
process.terminate()
try:
process.wait(timeout=60)
except subprocess.TimeoutExpired:
print("\033[91mProcess did not terminate in time, killing it.\033[0m")
process.kill()
rc = process.wait(timeout=60)
if rc:
raise RuntimeError(f"Training process exited with code {rc}")
except subprocess.TimeoutExpired as e:
print("\033[91mProcess did not terminate in time, killing it.\033[0m")
process.kill()
raise RuntimeError("Training process timed out on exit.") from e


if __name__ == "__main__":
Expand Down