Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -3,8 +3,10 @@ import os
|
|
| 3 |
import json
|
| 4 |
import torch
|
| 5 |
import subprocess
|
|
|
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
import logging
|
|
|
|
| 8 |
|
| 9 |
# Configure logging
|
| 10 |
logging.basicConfig(
|
|
@@ -38,16 +40,39 @@ model_config = config.get("model_config", {})
|
|
| 38 |
MODEL_NAME = model_config.get("model_name_or_path", "unsloth/DeepSeek-R1-Distill-Qwen-14B-bnb-4bit")
|
| 39 |
SPACE_NAME = os.getenv("HF_SPACE_NAME", "phi4training")
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
# Function to start the training process
|
| 42 |
def start_training():
|
| 43 |
try:
|
| 44 |
-
#
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
# Log the start of training
|
| 49 |
-
logger.info("Training started
|
| 50 |
-
print("Training process initiated! This will appear in Hugging Face logs.")
|
| 51 |
|
| 52 |
return """
|
| 53 |
✅ Training process initiated!
|
|
@@ -56,7 +81,7 @@ def start_training():
|
|
| 56 |
|
| 57 |
To monitor progress:
|
| 58 |
1. Check the Hugging Face space logs in the "Logs" tab
|
| 59 |
-
2.
|
| 60 |
3. The process will continue running in the background
|
| 61 |
|
| 62 |
NOTE: This is a research training phase only, no model outputs will be available.
|
|
@@ -121,6 +146,8 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
|
|
| 121 |
# Launch the interface
|
| 122 |
if __name__ == "__main__":
|
| 123 |
# Start Gradio with minimal features
|
|
|
|
|
|
|
|
|
|
| 124 |
logger.info("Starting research training dashboard")
|
| 125 |
-
print("Research training dashboard started - Logs will be visible here")
|
| 126 |
demo.launch(share=False)
|
|
|
|
| 3 |
import json
|
| 4 |
import torch
|
| 5 |
import subprocess
|
| 6 |
+
import sys
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
import logging
|
| 9 |
+
import threading
|
| 10 |
|
| 11 |
# Configure logging
|
| 12 |
logging.basicConfig(
|
|
|
|
| 40 |
MODEL_NAME = model_config.get("model_name_or_path", "unsloth/DeepSeek-R1-Distill-Qwen-14B-bnb-4bit")
|
| 41 |
SPACE_NAME = os.getenv("HF_SPACE_NAME", "phi4training")
|
| 42 |
|
| 43 |
+
# Function to run training in a thread and stream output to container logs
|
| 44 |
+
def run_training():
|
| 45 |
+
"""Run the training script and stream its output to container logs"""
|
| 46 |
+
process = subprocess.Popen(
|
| 47 |
+
["python", "run_cloud_training.py"],
|
| 48 |
+
stdout=subprocess.PIPE,
|
| 49 |
+
stderr=subprocess.STDOUT,
|
| 50 |
+
universal_newlines=True,
|
| 51 |
+
bufsize=1
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
# Stream output directly to sys.stdout (container logs)
|
| 55 |
+
for line in iter(process.stdout.readline, ''):
|
| 56 |
+
sys.stdout.write(line)
|
| 57 |
+
sys.stdout.flush()
|
| 58 |
+
|
| 59 |
# Function to start the training process
|
| 60 |
def start_training():
|
| 61 |
try:
|
| 62 |
+
# Print directly to container logs
|
| 63 |
+
print("\n===== STARTING TRAINING PROCESS =====\n")
|
| 64 |
+
print(f"Model: {MODEL_NAME}")
|
| 65 |
+
print(f"Training with configuration from transformers_config.json")
|
| 66 |
+
print("Training logs will appear below:")
|
| 67 |
+
print("=" * 50)
|
| 68 |
+
|
| 69 |
+
# Start training in a separate thread
|
| 70 |
+
training_thread = threading.Thread(target=run_training)
|
| 71 |
+
training_thread.daemon = True # Allow the thread to be terminated when app exits
|
| 72 |
+
training_thread.start()
|
| 73 |
|
| 74 |
# Log the start of training
|
| 75 |
+
logger.info("Training started in background thread")
|
|
|
|
| 76 |
|
| 77 |
return """
|
| 78 |
✅ Training process initiated!
|
|
|
|
| 81 |
|
| 82 |
To monitor progress:
|
| 83 |
1. Check the Hugging Face space logs in the "Logs" tab
|
| 84 |
+
2. You should see training output appearing directly in the logs
|
| 85 |
3. The process will continue running in the background
|
| 86 |
|
| 87 |
NOTE: This is a research training phase only, no model outputs will be available.
|
|
|
|
| 146 |
# Launch the interface
|
| 147 |
if __name__ == "__main__":
|
| 148 |
# Start Gradio with minimal features
|
| 149 |
+
print("\n===== RESEARCH TRAINING DASHBOARD STARTED =====\n")
|
| 150 |
+
print("Click 'Start Training' to begin the fine-tuning process")
|
| 151 |
+
print("All training output will appear in these logs")
|
| 152 |
logger.info("Starting research training dashboard")
|
|
|
|
| 153 |
demo.launch(share=False)
|