Automation foundation model for tiny devices: 2-bit, 8-29 MB, tool calls, ASR, structured extraction and embeddings on phones, wearables, smart homes, robots, cars and microcontrollers.
updates
HenryNdubuakue7a5dd8eb233
diff --git a/src/cli.py b/src/cli.pyindex 854fee3..2299092 100644--- a/src/cli.py+++ b/src/cli.py@@ -1,11 +1,100 @@import argparseimport os+import reimport sys+import threadingfrom .data import DEFAULT_MAX_ENC_LEN, DEFAULT_MAX_DEC_LEN, DEFAULT_MAX_GEN_LENHELP = """Check the readme"""++_ABSL_LOG_START = re.compile(rb"^[EIWF]\d{4} \d\d:\d\d:\d\d")+_NOISY_LOG_HEADER = re.compile(+ rb"\] (?:Fusion: .*gemm_fusion|Computation: .*_computation|Delay kernel timed out)"+)++_log_filter_installed = False+++def _install_xla_log_filter():+ """Drop XLA Triton autotuner noise from stderr.++ XLA's Triton GEMM autotuner logs failed candidate fusions via LOG(ERROR)+ in xtile_compiler.cc and cuda_timer.cc. These are unconditional and do+ not respect TF_CPP_MIN_LOG_LEVEL, so we filter them at the file+ descriptor level.++ Strategy:+ - Rebind Python's sys.stderr to a fresh file object over the real+ terminal fd, so tqdm and print() writes go straight to the terminal+ and never enter our pipe. This keeps progress bars (which use \\r+ without trailing \\n) from stalling the filter's line parser.+ - Replace fd 2 with a pipe. Only C-level writes (absl / XLA LOG(...))+ now flow through the pipe, and they are always \\n-terminated and+ well-formed, so a simple line-based filter is reliable.+ """+ global _log_filter_installed+ if _log_filter_installed:+ return+ _log_filter_installed = True++ # 1. Dup the original stderr fd; rebind Python's sys.stderr to it so+ # all Python-level writes bypass the pipe.+ py_stderr_fd = os.dup(2)+ try:+ sys.stderr.flush()+ except Exception:+ pass+ sys.stderr = os.fdopen(py_stderr_fd, "w", encoding="utf-8",+ errors="replace", buffering=1)++ # 2. Dup another copy for the filter thread to write filtered C-level+ # output to.+ out_fd = os.dup(2) # before dup2 below, fd 2 is still the real terminal++ # 3. Redirect fd 2 to the write end of a new pipe. All C-level writes+ # from XLA now land in the pipe.+ r_fd, w_fd = os.pipe()+ os.dup2(w_fd, 2)+ os.close(w_fd)++ def pump():+ reader = os.fdopen(r_fd, "rb", buffering=0)+ out = os.fdopen(out_fd, "wb", buffering=0)+ buf = b""+ skipping = False+ try:+ while True:+ chunk = reader.read(65536)+ if not chunk:+ break+ buf += chunk+ while True:+ idx = buf.find(b"\n")+ if idx == -1:+ break+ line = bytes(buf[:idx])+ buf = buf[idx + 1:]+ is_log_start = bool(_ABSL_LOG_START.match(line))+ if skipping:+ if is_log_start:+ if _NOISY_LOG_HEADER.search(line):+ continue+ skipping = False+ out.write(line + b"\n")+ # else: continuation body of a skipped log block — drop+ else:+ if is_log_start and _NOISY_LOG_HEADER.search(line):+ skipping = True+ continue+ out.write(line + b"\n")+ except Exception:+ pass++ t = threading.Thread(target=pump, daemon=True, name="xla-log-filter")+ t.start()+def main():if len(sys.argv) < 2 or sys.argv[1] in ("-h", "--help", "help"):print(HELP)@@ -245,12 +334,18 @@ def main():from .tokenize_data import tokenizetokenize(args)elif args.command == "pretrain":+ os.environ.setdefault("TF_CPP_MIN_LOG_LEVEL", "2")+ os.environ.setdefault("GRPC_VERBOSITY", "ERROR")+ _install_xla_log_filter()import jaxif os.path.exists("/dev/accel0"):jax.distributed.initialize()from .pretrain import pretrainpretrain(args)elif args.command == "train":+ os.environ.setdefault("TF_CPP_MIN_LOG_LEVEL", "2")+ os.environ.setdefault("GRPC_VERBOSITY", "ERROR")+ _install_xla_log_filter()import jaxif os.path.exists("/dev/accel0"):jax.distributed.initialize()