CoolFace
Apppublic

NorthernTribe-Research/medical-reasoning-trainer

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
App README

<!-- author: Muzan Sano -->

Medical Reasoning Trainer

This Space provides a robust training + monitoring dashboard for NorthernTribe-Medical-Reasoning-7B.

What It Does

  • Runs a Gradio control panel for:
  • training lifecycle management (start/stop)
  • real-time loss and log monitoring
  • model inference (adapter or base model)
  • Supports automatic training start on boot (AUTO_START_TRAINING=1)
  • Handles no-GPU environments gracefully (dashboard still runs, training is blocked with clear status)

Required Space Secrets

  • HF_TOKEN (recommended): used for Hub authentication and model push workflows.

Runtime Environment Variables

  • AUTO_START_TRAINING: 1 to auto-start training when app launches (default 1)
  • TRAINING_AUTONOMOUS_24X7: 1 forces always-on training supervision/restart behavior (default 1)
  • APP_TIMEZONE: dashboard/status timezone (default Africa/Nairobi, i.e., East Africa Time)
  • UI_REFRESH_SECONDS: telemetry refresh cadence in dashboard tabs (default 3)
  • TRAIN_MONITOR_MAX_POINTS: max points rendered in live training graph (default 2500)
  • AUTO_ENSURE_TRAINING: 1 enables watchdog auto-restart if training process stops (default 1)
  • ENSURE_TRAINING_INTERVAL_SECONDS: watchdog check interval in seconds (default 20)
  • WATCHDOG_MAX_FAILURES: failures inside the watchdog window before restart backoff is applied (default 3)
  • WATCHDOG_FAILURE_WINDOW_SECONDS: failure counting window for watchdog backoff (default 300)
  • WATCHDOG_BACKOFF_SECONDS: pause duration before watchdog retries after repeated failures (default 45)
  • TRAINING_STALL_TIMEOUT_SECONDS: if no telemetry/log activity for this long, watchdog treats training as stalled and restarts it (default 900, set 0 to disable)
  • RUN_TRAINING_ONLY: 1 to run only train_medical_model.py (no UI)
  • TRAINING_SCRIPT: override training script path (default train_medical_model.py)
  • ALLOW_CPU_TRAINING: 1 to allow CPU-mode training fallback when no GPU is present (default 1)
  • FORCE_CPU_TRAINING: 1 to force CPU-mode training even when a GPU exists
  • CPU_BASE_MODEL_NAME: CPU fallback model for transformer training (default sshleifer/tiny-gpt2)
  • CPU_LOCAL_FILES_ONLY: 1 to avoid Hub downloads and use only cached/local CPU model files
  • CPU_ALLOW_CHAR_FALLBACK: 1 to permit fully local char-level fallback training if transformer CPU setup fails
  • TRAINING_LOOP: 1 to run training cycles continuously (default 1)
  • TRAINING_LOOP_ON_CPU_ONLY: 1 to loop only when runtime mode is CPU (default 0)
  • TRAINING_LOOP_SLEEP_SECONDS: pause between cycles (default 10)
  • TRAINING_LOOP_MAX_CYCLES: max cycles before exit (0 = infinite / 24x7)
  • INFERENCE_BACKEND: auto, unsloth, or llama_cpp (default auto)
  • LLAMA_CPP_BIN: path to llama-cli binary (default /opt/llama.cpp/build/bin/llama-cli)
  • LLAMA_CPP_MODEL: path to GGUF model file to use with llama.cpp
  • LLAMA_CPP_CTX: context size for llama.cpp (default 4096)
  • LLAMA_CPP_THREADS: threads for llama.cpp (default 4)
  • LLAMA_CPP_MAX_TOKENS: max generated tokens for llama.cpp (default 512)
  • LLAMA_CPP_TEMPERATURE: llama.cpp temperature (default 0.3)
  • LLAMA_CPP_TOP_P: llama.cpp top-p (default 0.9)
  • LLAMA_CPP_TIMEOUT: inference timeout seconds for llama.cpp command execution
  • LLAMA_CPP_EXTRA_ARGS: extra CLI args appended to llama-cli

Notes

  • GPU is required for Unsloth fine-tuning and practical 7B inference.
  • CPU training is supported with a smaller fallback training path for no-GPU environments.
  • Runtime dependency versions are pinned in requirements.txt to avoid Torch/Transformers compatibility regressions.
  • In TRAINING_AUTONOMOUS_24X7=1, run_training.sh also supervises the dashboard/training process and relaunches it if it exits.
  • For better data quality before training, run: ./venv/bin/python refine_local_dataset.py --input merged_health_dataset_sample.jsonl --output merged_health_dataset_refined.jsonl
  • To merge refined + main into one update-ready dataset file, run: ./venv/bin/python merge_main_and_refined_dataset.py --main merged_health_dataset_sample.jsonl --refined merged_health_dataset_refined.jsonl --output merged_health_dataset_merged.jsonl
  • Then update the existing HF dataset repo (same repo, new commit): ./venv/bin/python upload_dataset.py --dataset-path merged_health_dataset_merged.jsonl --repo-name comprehensive-healthbench-v2
  • llama.cpp inference uses GGUF models. Set LLAMA_CPP_MODEL to a valid .gguf file path in the Space.
  • You can convert a local HF model directory to GGUF with: python convert_to_gguf.py --model-dir NorthernTribe-Medical-Reasoning-7B-output --output /app/models/medical.gguf --outtype f16 --quantize Q4_K_M