66"""
77
88from contextlib import contextmanager
9+ import os
910from typing import Any , Dict , List , Optional , Union
10- import time
1111
1212from rich .console import Console
1313from rich .progress import (
@@ -187,6 +187,12 @@ def __init__(self, console: Optional[Console] = None):
187187 """
188188 self .console = console or Console ()
189189 self .progress_manager : Optional [RichProgress ] = None
190+ self ._plain_output = (
191+ os .environ .get ("GITHUB_ACTIONS" ) == "true" or os .environ .get ("CI" ) == "true"
192+ )
193+
194+ def _emit (self , message : str ):
195+ print (message , flush = True )
190196
191197 @contextmanager
192198 def track_dataset_creation (self , datasets : List [str ]):
@@ -198,6 +204,23 @@ def track_dataset_creation(self, datasets: List[str]):
198204 Yields:
199205 Tuple of (update_dataset function, progress manager for nested tasks).
200206 """
207+ if self ._plain_output :
208+ completed_count = 0
209+
210+ def update_dataset (dataset_name : str , status : str = "processing" ):
211+ nonlocal completed_count
212+
213+ if status == "processing" :
214+ self ._emit (f"[dataset] starting: { dataset_name } " )
215+ elif status == "completed" :
216+ completed_count += 1
217+ self ._emit (
218+ f"[dataset] completed ({ completed_count } /{ len (datasets )} ): { dataset_name } "
219+ )
220+
221+ yield update_dataset , None
222+ return
223+
201224 with create_progress (self .console ) as progress :
202225 # Main dataset creation progress
203226 main_task = progress .add_task (
@@ -265,6 +288,27 @@ def track_calibration(self, iterations: int, nested_progress=None):
265288 Yields:
266289 Function to update calibration progress.
267290 """
291+ if self ._plain_output :
292+
293+ def update_calibration (
294+ iteration : int ,
295+ loss_value : Optional [float ] = None ,
296+ calculating_loss : bool = False ,
297+ ):
298+ if calculating_loss :
299+ self ._emit (
300+ f"[calibration] epoch { iteration } /{ iterations } : calculating loss"
301+ )
302+ elif loss_value is not None and (
303+ iteration == 1 or iteration == iterations or iteration % 10 == 0
304+ ):
305+ self ._emit (
306+ f"[calibration] epoch { iteration } /{ iterations } : loss={ loss_value :.6f} "
307+ )
308+
309+ yield update_calibration
310+ return
311+
268312 if nested_progress :
269313 # Add calibration as a nested task in existing progress
270314 calibration_task = nested_progress .add_task (
0 commit comments