File size: 3,252 Bytes
fd357f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
"""
Individual file upload script for Xet backend compatibility
Uploads files one by one to avoid folder upload limitations
"""

import os
import logging
from pathlib import Path
from huggingface_hub import HfApi, upload_file

# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

def upload_individual_files():
    """Upload individual model files to HF Hub"""
    
    # Get HF token
    token = os.getenv('HF_TOKEN')
    if not token:
        raise ValueError("HF_TOKEN environment variable not set")
    
    api = HfApi(token=token)
    repo_id = "LevelUp2x/dto-models"
    
    # Find all model files (excluding extremely large ones)
    model_files = []
    experiments_path = "/data/experiments"
    
    if os.path.exists(experiments_path):
        for root, _, files in os.walk(experiments_path):
            for file in files:
                if file.endswith(('.safetensors', '.pt', '.bin')):
                    file_path = os.path.join(root, file)
                    try:
                        file_size = os.path.getsize(file_path)
                        # Skip files larger than 10GB
                        if file_size > 10 * 1024**3:
                            logger.warning(f"Skipping extremely large file: {file_path} ({file_size/1024**3:.1f}GB)")
                            continue
                        model_files.append(file_path)
                    except OSError:
                        logger.warning(f"Could not get size for {file_path}")
    
    logger.info(f"Found {len(model_files)} model files to upload")
    
    # Upload files individually
    success_count = 0
    failed_count = 0
    
    for file_path in model_files:
        try:
            # Create repository path
            rel_path = file_path.replace('/data/experiments/', '')
            
            logger.info(f"Uploading: {file_path} -> {repo_id}/{rel_path}")
            
            # Upload individual file
            upload_file(
                path_or_fileobj=file_path,
                path_in_repo=rel_path,
                repo_id=repo_id,
                token=token,
                commit_message=f"DTO Archive: Uploading {os.path.basename(file_path)}"
            )
            
            logger.info(f"✅ Successfully uploaded {file_path}")
            success_count += 1
            
        except Exception as e:
            logger.error(f"❌ Failed to upload {file_path}: {e}")
            failed_count += 1
    
    logger.info(f"Upload Summary: {success_count} successful, {failed_count} failed")
    
    if success_count > 0:
        logger.info("✅ Individual file upload completed successfully")
    else:
        logger.error("❌ Individual file upload failed completely")

if __name__ == "__main__":
    # Load environment variables
    env_file = "/data/adaptai/platform/dataops/dto/.env"
    if os.path.exists(env_file):
        with open(env_file) as f:
            for line in f:
                if line.strip() and not line.startswith('#'):
                    key, value = line.strip().split('=', 1)
                    os.environ[key] = value
    
    upload_individual_files()