From ae0a39d1b45eb74b1104618e03ccba4cae85260e Mon Sep 17 00:00:00 2001 From: Pierre-Louis <78484833+PierreLouisLetoquart@users.noreply.github.com> Date: Fri, 28 Feb 2025 10:54:16 -0500 Subject: [PATCH] chore(lora): Add real-time log buffering fix for nohup execution Disable Python stdout buffering to ensure logs appear in nohup.out in real-time instead of only after script completion. --- lora/lora.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lora/lora.py b/lora/lora.py index 723e783d..5f3a5c01 100644 --- a/lora/lora.py +++ b/lora/lora.py @@ -1,5 +1,7 @@ # Copyright © 2023-2024 Apple Inc. +import os +import sys import argparse import json import math @@ -15,6 +17,12 @@ from mlx.utils import tree_flatten from models import LoRALinear +# Disable output buffering to see print statements in real-time +if sys.version_info >= (3, 7): + sys.stdout.reconfigure(line_buffering=True) +else: + sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1) + def build_parser(): parser = argparse.ArgumentParser(description="LoRA or QLoRA finetuning.") parser.add_argument(