NorthernTribe-Research/medical-reasoning-trainer
0
<!-- 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:1to auto-start training when app launches (default1)TRAINING_AUTONOMOUS_24X7:1forces always-on training supervision/restart behavior (default1)APP_TIMEZONE: dashboard/status timezone (defaultAfrica/Nairobi, i.e., East Africa Time)UI_REFRESH_SECONDS: telemetry refresh cadence in dashboard tabs (default3)TRAIN_MONITOR_MAX_POINTS: max points rendered in live training graph (default2500)AUTO_ENSURE_TRAINING:1enables watchdog auto-restart if training process stops (default1)ENSURE_TRAINING_INTERVAL_SECONDS: watchdog check interval in seconds (default20)WATCHDOG_MAX_FAILURES: failures inside the watchdog window before restart backoff is applied (default3)WATCHDOG_FAILURE_WINDOW_SECONDS: failure counting window for watchdog backoff (default300)WATCHDOG_BACKOFF_SECONDS: pause duration before watchdog retries after repeated failures (default45)TRAINING_STALL_TIMEOUT_SECONDS: if no telemetry/log activity for this long, watchdog treats training as stalled and restarts it (default900, set0to disable)RUN_TRAINING_ONLY:1to run onlytrain_medical_model.py(no UI)TRAINING_SCRIPT: override training script path (defaulttrain_medical_model.py)ALLOW_CPU_TRAINING:1to allow CPU-mode training fallback when no GPU is present (default1)FORCE_CPU_TRAINING:1to force CPU-mode training even when a GPU existsCPU_BASE_MODEL_NAME: CPU fallback model for transformer training (defaultsshleifer/tiny-gpt2)CPU_LOCAL_FILES_ONLY:1to avoid Hub downloads and use only cached/local CPU model filesCPU_ALLOW_CHAR_FALLBACK:1to permit fully local char-level fallback training if transformer CPU setup failsTRAINING_LOOP:1to run training cycles continuously (default1)TRAINING_LOOP_ON_CPU_ONLY:1to loop only when runtime mode is CPU (default0)TRAINING_LOOP_SLEEP_SECONDS: pause between cycles (default10)TRAINING_LOOP_MAX_CYCLES: max cycles before exit (0= infinite / 24x7)INFERENCE_BACKEND:auto,unsloth, orllama_cpp(defaultauto)LLAMA_CPP_BIN: path tollama-clibinary (default/opt/llama.cpp/build/bin/llama-cli)LLAMA_CPP_MODEL: path to GGUF model file to use with llama.cppLLAMA_CPP_CTX: context size for llama.cpp (default4096)LLAMA_CPP_THREADS: threads for llama.cpp (default4)LLAMA_CPP_MAX_TOKENS: max generated tokens for llama.cpp (default512)LLAMA_CPP_TEMPERATURE: llama.cpp temperature (default0.3)LLAMA_CPP_TOP_P: llama.cpp top-p (default0.9)LLAMA_CPP_TIMEOUT: inference timeout seconds for llama.cpp command executionLLAMA_CPP_EXTRA_ARGS: extra CLI args appended tollama-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.txtto avoid Torch/Transformers compatibility regressions. - In
TRAINING_AUTONOMOUS_24X7=1,run_training.shalso 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_MODELto a valid.gguffile 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
