#!/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()