🧠 Alegbra-1.2 : The Smart Meta-Learning Merger AI

Alegbra-1.2 Banner Alegbra-1.2 is a lightweight, high-performance Artificial Intelligence (~81 MB / ~10 Million Parameters) specifically designed to act as a "Smart Brain" for merging SDXL U-Net models.

Instead of relying on manual, flat-ratio merging (like 0.5) or guessing block weights, Alegbra-1.2 reads the mathematical structure of two massive SDXL models, calculates their differences, and dynamically predicts the most perfect fusion ratio (Alpha) for every single tensor.

⚠️ IMPORTANT WARNING: VERSION CONTROL

DO NOT DOWNLOAD OR USE ANY VERSIONS BELOW 1.2 (v1.0 or v1.1). > Previous versions were experimental and suffered from NaN (Not a Number) overflow and Latent Space Collapse issues. Alegbra-1.2 is the only stable, production-ready version equipped with TPU-level Anti-NaN Math Armor and Gradient Clipping.


πŸš€ Key Features

  1. Zero Deepfried & Artifacts: Alegbra-1.2 utilizes Weight Variance Loss and Cosine Similarity to detect "clashing" weights between models. It automatically adjusts the Alpha ratio to prevent color burning (deepfried) and anatomical collapse.
  2. Dynamic Cross-Attention: Built on a Multi-Head Attention Mini-Transformer architecture. It understands the hierarchy of SDXL blocks (Input, Middle, Output) and balances them holistically.
  3. Hardware Agnostic: While trained natively on Google Kaggle TPU v5e-8, this model runs perfectly on CPU, NVIDIA GPU, and AMD GPU via JAX/Flax.
  4. FP32 Precision Core: All internal mathematical evaluations are done in pure Float32 before safely converting the final merged model back to FP16.

πŸ—οΈ Architecture & Training Specs

  • Model Type: Meta-Learning Merging Agent (JAX / Flax)
  • Parameters: ~10 Million
  • Size: 81.07 MB
  • Input: Tensor Statistical Context [Mean Diff, Variance Diff, L2 Norm Diff, Cosine Sim]
  • Output: Sigmoid Alpha Ratio (0.0 to 1.0)
  • Training Hardware: TPU v5e-8 & 224-Core CPU Enterprise (RAM Disk /dev/shm)
  • Creator: Bl4ckSpaces

πŸ› οΈ Tutorial: How to Use Alegbra-1.2

To use Alegbra-1.2 to merge your own SDXL models, you need an executor script. Below is the official Python inference code.

Prerequisites

Make sure you have installed the required dependencies:

pip install jax flax huggingface_hub safetensors numpy requests
(Note: Install jax[cuda] or jax[tpu] if you want hardware acceleration, otherwise standard JAX will run on CPU).
Inference Code (Executor Script)
import jax
import jax.numpy as jnp
from flax import linen as nn
from safetensors.numpy import load_file, save_file
import numpy as np

# 1. DEFINE THE ARCHITECTURE
class Alegbra1(nn.Module):
    @nn.compact
    def __call__(self, x):
        x = nn.Dense(1024)(x)
        x = nn.relu(x)
        x = nn.Dense(2048)(x)
        x = nn.relu(x)
        x_attn = jnp.expand_dims(x, axis=1)
        attn_out = nn.MultiHeadDotProductAttention(num_heads=16)(x_attn, x_attn)
        x = jnp.squeeze(attn_out, axis=1) + x 
        x = nn.Dense(1024)(x)
        x = nn.relu(x)
        x = nn.Dense(256)(x)
        x = nn.relu(x)
        return nn.sigmoid(nn.Dense(1)(x))

@jax.jit(static_argnums=(0,))
def get_alpha(model, params, ta, tb):
    # Extract mathematical statistics
    m_diff = jnp.abs(jnp.mean(ta) - jnp.mean(tb))
    v_diff = jnp.abs(jnp.var(ta) - jnp.var(tb))
    l2 = jnp.linalg.norm(ta - tb)
    cos = jnp.sum(ta * tb) / (jnp.linalg.norm(ta) * jnp.linalg.norm(tb) + 1e-8)
    
    # Anti-NaN Protection
    stats = jnp.array((m_diff, v_diff, l2, cos), dtype=jnp.float32)
    stats = jnp.clip(jnp.nan_to_num(stats, nan=1e5), a_min=-1e5, a_max=1e5)
    
    # Predict the perfect Alpha
    alpha = model.apply(params, jnp.expand_dims(stats, axis=0))
    return jnp.squeeze(alpha)

# 2. EXECUTION
def smart_merge(model_a_path, model_b_path, brain_path, output_path):
    print("Loading Alegbra-1.2 Brain...")
    brain_weights = load_file(brain_path)
    model = Alegbra1()
    
    # Reconstruct Flax parameters
    params_flat = {k: jnp.array(v) for k, v in brain_weights.items()}
    from flax.traverse_util import unflatten_dict
    params = unflatten_dict(params_flat, sep='.')

    print("Loading SDXL Models...")
    state_a = load_file(model_a_path)
    state_b = load_file(model_b_path)
    merged_dict = {}

    keys = list(set(state_a.keys()).intersection(set(state_b.keys())))
    
    print("Initiating Smart Fusion...")
    for i, key in enumerate(keys):
        ta = jnp.array(state_a[key])
        tb = jnp.array(state_b[key])
        
        if len(ta.shape) > 0:
            alpha = float(get_alpha(model, params, ta, tb))
            merged = ((1.0 - alpha) * ta) + (alpha * tb)
            merged_dict[key] = np.array(merged, dtype=np.float16) # Compress to FP16
        else:
            merged_dict[key] = np.array((ta + tb) / 2.0, dtype=np.float16)

    save_file(merged_dict, output_path)
    print(f"Fusion Complete! Saved to {output_path}")

# Run the function
# smart_merge("model_A.safetensors", "model_B.safetensors", "Alegbra-1_v1-2_TPU.safetensors", "AlegbraFusion.safetensors")
πŸ† Proven Results
Alegbra-1.2 was used to merge Illustrious and NoobAI, resulting in AlegbraFusion-XL. The AI successfully mitigated latent space collapse, retained solid hand anatomies, and delivered artifact-free pastel lighting without human intervention.
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support