Skip to content

r4k5O/CreateLLM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CreateLLM - AI Training Data Generation & Model Distillation Platform

CreateLLM is a comprehensive Flask application that leverages multiple AI services (Ollama, OpenAI, HuggingFace) to generate training data for model distillation. The platform supports hardware acceleration through GPUs and NPUs (Snapdragon X Elite, etc.) for optimal performance.

πŸš€ Key Features

  • πŸ€– Multi-AI Service Integration: Connect to OpenAI, Ollama, and HuggingFace models
  • πŸ“Š Training Data Generation: Create diverse training samples using different AI models
  • πŸ”„ Model Distillation: Distill knowledge from teacher to student models
  • ⚑ Hardware Acceleration: Automatic detection and utilization of GPUs and NPUs
  • πŸ–₯️ Web Interface: Intuitive dashboard for monitoring and configuration
  • 🌐 RESTful API: Complete API for programmatic access
  • πŸ“ˆ Real-time Status: Monitor system performance and AI service availability
  • πŸ”§ WSL Support: Full NPU support in Windows Subsystem for Linux

🎯 Special Features for Snapdragon X Elite

  • πŸ”₯ NPU Detection: Automatic detection of Qualcomm Hexagon NPU
  • πŸŒ‰ WSL Interop: NPU access through Windows Subsystem for Linux
  • ⚑ 2.5x Performance: Real NPU acceleration with 2.5x speedup factor
  • πŸ”§ Smart Fallback: Automatic CPU fallback when NPU unavailable

πŸ“‹ System Requirements

Minimum Requirements

  • Python 3.8+
  • 4GB RAM
  • 2GB disk space

Recommended Hardware

  • Snapdragon X Elite with Qualcomm Hexagon NPU βœ…
  • NVIDIA GPU with CUDA support
  • Apple Silicon (M1/M2/M3) with MPS
  • 16GB+ RAM for large datasets

Supported Platforms

  • Windows 10/11 (Full NPU support)
  • WSL2 (NPU via Windows interop) βœ…
  • Linux (GPU/CPU support)
  • macOS (Apple Silicon GPU support)

πŸ› οΈ Installation

Quick Start (Basic)

# Clone the repository
git clone https://github.com/r4k5O/CreateLLM.git
cd CreateLLM

# Install basic dependencies
pip install Flask Flask-CORS requests numpy scikit-learn pandas pydantic python-dotenv aiohttp psutil WMI

# Install AI services
pip install openai ollama

# Run the application
python3 app.py

Full Installation (Recommended)

# Install all dependencies
pip install -r requirements.txt

# Optional: Install ML acceleration libraries
pip install torch torchvision transformers datasets accelerate bitsandbytes GPUtil

# Configure environment
cp .env.example .env
# Edit .env with your API keys

Snapdragon X Elite NPU Setup

# For WSL users (recommended)
# The system will automatically detect your Snapdragon NPU via Windows interop

# Manual NPU enablement (if auto-detection fails)
echo "FORCE_NPU=true" >> .env

# Verify NPU detection
python3 test_wsl_npu.py

βš™οΈ Configuration

Environment Variables

Create a .env file with the following:

# AI Service Configuration
OPENAI_API_KEY=your_openai_api_key_here
OLLAMA_HOST=http://localhost:11434
HUGGINGFACE_TOKEN=your_huggingface_token_here

# Model Parameters
MAX_TOKENS=2048
TEMPERATURE=0.7
BATCH_SIZE=8

# Hardware Acceleration
USE_GPU=true
USE_NPU=true
FORCE_NPU=false  # Set to true to force NPU enablement

# System Configuration
OUTPUT_DIR=./output
LOG_LEVEL=INFO

Hardware Priority

The system automatically selects the best available hardware:

  1. NPU (Snapdragon X Elite Hexagon) - Highest priority
  2. CUDA GPU (NVIDIA)
  3. MPS GPU (Apple Silicon)
  4. CPU (Fallback)

🌐 Usage

Web Interface

  1. Start the application: python3 app.py
  2. Open browser: http://localhost:5000
  3. Use the dashboard to:
    • Monitor hardware acceleration status
    • Generate training data
    • Perform model distillation
    • Configure settings

API Usage

Generate Training Data

curl -X POST http://localhost:5000/api/generate \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Explain quantum computing",
    "source_model": "ollama",
    "target_model": "openai",
    "count": 10
  }'

Model Distillation

curl -X POST http://localhost:5000/api/distill \
  -H "Content-Type: application/json" \
  -d '{
    "teacher_model": "openai",
    "student_model": "ollama",
    "training_data": [...]
  }'

System Status

curl http://localhost:5000/api/status

Available Models

curl http://localhost:5000/api/models

Python SDK

import requests

# Generate training data
response = requests.post('http://localhost:5000/api/generate', json={
    'prompt': 'What are the benefits of renewable energy?',
    'source_model': 'ollama',
    'target_model': 'openai',
    'count': 20
})

data = response.json()
print(f"Generated {data['count']} training samples")

# Model distillation
training_data = [...]  # Your training data
response = requests.post('http://localhost:5000/api/distill', json={
    'teacher_model': 'openai',
    'student_model': 'ollama',
    'training_data': training_data
})

result = response.json()
print(f"Distillation similarity: {result['result']['average_similarity']:.3f}")

πŸ—οΈ Architecture

CreateLLM/
β”œβ”€β”€ app.py                      # Main Flask application
β”œβ”€β”€ requirements.txt            # Python dependencies
β”œβ”€β”€ .env.example               # Environment template
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ ai_manager.py          # AI service integrations
β”‚   β”œβ”€β”€ data_generator.py      # Training data generation
β”‚   β”œβ”€β”€ distillation_engine.py # Model distillation
β”‚   β”œβ”€β”€ hardware_accelerator.py # Hardware acceleration
β”‚   └── npu_backend.py         # NPU execution backend
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ config.py              # Configuration management
β”‚   └── logger.py              # Logging utilities
β”œβ”€β”€ templates/
β”‚   └── index.html             # Web interface
β”œβ”€β”€ static/                    # Static assets
β”œβ”€β”€ output/                    # Generated data files
β”œβ”€β”€ test_wsl_npu.py           # WSL NPU detection test
└── README.md                 # This file

πŸ“Š API Endpoints

Method Endpoint Description
GET / Web interface
GET /api/status System status and hardware info
POST /api/generate Generate training data
POST /api/distill Perform model distillation
GET /api/models List available models
GET /api/config Get configuration
POST /api/config Update configuration

πŸ” Hardware Detection

Automatic Detection

The system automatically detects:

  • NPU: Snapdragon X Elite Hexagon via WSL interop
  • GPU: NVIDIA CUDA, Apple Silicon MPS
  • CPU: Core count, memory, architecture

Detection Commands

# Test NPU detection (WSL)
python3 test_wsl_npu.py

# Enhanced hardware detection
python3 test_npu_enhanced.py

# Basic system check
python3 -c "
from services.hardware_accelerator import HardwareAccelerator
info = HardwareAccelerator().get_info()
print(f'Device: {info[\"device\"]}')
print(f'NPU Available: {info[\"npu_available\"]}')
"

Expected Output (Snapdragon X Elite)

{
  "device": "npu",
  "npu_available": true,
  "npu_backend": {
    "type": "Qualcomm Snapdragon NPU",
    "available": true,
    "wsl_mode": true,
    "performance_factor": 2.5,
    "supported_operations": ["matrix_multiply", "neural_inference", "tensor_operation"]
  }
}

πŸš€ Performance Optimization

NPU Optimization (Snapdragon X Elite)

  • 2.5x speedup for matrix operations
  • WSL interop for Windows NPU access
  • Smart batching for optimal throughput
  • Memory management for large models

GPU Optimization

  • CUDA acceleration for NVIDIA GPUs
  • Memory pooling for reduced allocation overhead
  • Batch size optimization based on GPU memory
  • Mixed precision for faster inference

General Optimization

  • Concurrent processing for multiple AI services
  • Intelligent caching for repeated operations
  • Resource monitoring for optimal performance
  • Automatic fallback when hardware unavailable

πŸ§ͺ Testing

Unit Tests

# Test hardware detection
python3 test_wsl_npu.py
python3 test_npu_enhanced.py

# Test AI services
python3 -c "
from services.ai_manager import AIManager
from utils.config import Config
manager = AIManager(Config())
print('Services:', manager.get_status())
"

Integration Tests

# Test API endpoints
curl http://localhost:5000/api/status
curl http://localhost:5000/api/models

# Test data generation
curl -X POST http://localhost:5000/api/generate \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Test", "count": 1}'

πŸ”§ Troubleshooting

Common Issues

NPU Not Detected

# Force enable NPU
echo "FORCE_NPU=true" >> .env

# Check WSL interop
python3 test_wsl_npu.py

# Verify Windows NPU drivers
# Check Device Manager for "Qualcomm Adreno GPU"

Import Errors

# Install missing dependencies
pip install -r requirements.txt

# For NPU support in WSL
pip install WMI

# For GPU acceleration
pip install torch torchvision

Performance Issues

# Check hardware status
curl http://localhost:5000/api/status

# Monitor resource usage
htop  # Linux/Mac
Task Manager  # Windows

# Optimize batch size
# Edit BATCH_SIZE in .env

Debug Mode

# Enable debug logging
echo "LOG_LEVEL=DEBUG" >> .env

# Run with Flask debug
python3 app.py  # Debug mode enabled by default

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Development Setup

# Clone and setup
git clone https://github.com/r4k5O/CreateLLM.git
cd CreateLLM
python3 -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt

# Development server
python3 app.py

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Qualcomm - Snapdragon X Elite NPU technology
  • Ollama - Local AI model serving
  • OpenAI - GPT API access
  • HuggingFace - Open model ecosystem
  • Flask - Web framework
  • WSL Team - Windows Subsystem for Linux

πŸ“ž Support

Getting Help

  • πŸ“‹ Issues: Create an issue on GitHub
  • πŸ“– Documentation: Check this README and inline comments
  • πŸ” Debugging: Enable debug mode with LOG_LEVEL=DEBUG
  • πŸ§ͺ Testing: Run the test scripts to verify setup

Performance Tuning

  1. Hardware: Ensure NPU/GPU drivers are up to date
  2. Batch Size: Adjust BATCH_SIZE based on your hardware
  3. Memory: Monitor RAM usage with large datasets
  4. Models: Choose appropriate model sizes for your hardware

πŸŽ‰ Quick Start Summary

# 1. Install
pip install Flask Flask-CORS requests openai ollama numpy scikit-learn

# 2. Configure
cp .env.example .env
# Edit .env with your API keys

# 3. Run
python3 app.py

# 4. Access
# Web: http://localhost:5000
# API: http://localhost:5000/api/status

πŸš€ Your CreateLLM platform is ready for AI training data generation and model distillation with full Snapdragon X Elite NPU acceleration!

About

With CreateLLM, you can now create your own distil models. Try it out now using your NPU (or Apples thingy), GPU or CPU!

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors