Views
No views yet
Alpha) for every single tensor.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.
[Mean Diff, Variance Diff, L2 Norm Diff, Cosine Sim](0.0 to 1.0)1pip install jax flax huggingface_hub safetensors numpy requests
2(Note: Install jax[cuda] or jax[tpu] if you want hardware acceleration, otherwise standard JAX will run on CPU).
3Inference Code (Executor Script)
4import jax
5import jax.numpy as jnp
6from flax import linen as nn
7from safetensors.numpy import load_file, save_file
8import numpy as np
9
10# 1. DEFINE THE ARCHITECTURE
11class Alegbra1(nn.Module):
12 @nn.compact
13 def __call__(self, x):
14 x = nn.Dense(1024)(x)
15 x = nn.relu(x)
16 x = nn.Dense(2048)(x)
17 x = nn.relu(x)
18 x_attn = jnp.expand_dims(x, axis=1)
19 attn_out = nn.MultiHeadDotProductAttention(num_heads=16)(x_attn, x_attn)
20 x = jnp.squeeze(attn_out, axis=1) + x
21 x = nn.Dense(1024)(x)
22 x = nn.relu(x)
23 x = nn.Dense(256)(x)
24 x = nn.relu(x)
25 return nn.sigmoid(nn.Dense(1)(x))
26
27@jax.jit(static_argnums=(0,))
28def get_alpha(model, params, ta, tb):
29 # Extract mathematical statistics
30 m_diff = jnp.abs(jnp.mean(ta) - jnp.mean(tb))
31 v_diff = jnp.abs(jnp.var(ta) - jnp.var(tb))
32 l2 = jnp.linalg.norm(ta - tb)
33 cos = jnp.sum(ta * tb) / (jnp.linalg.norm(ta) * jnp.linalg.norm(tb) + 1e-8)
34
35 # Anti-NaN Protection
36 stats = jnp.array((m_diff, v_diff, l2, cos), dtype=jnp.float32)
37 stats = jnp.clip(jnp.nan_to_num(stats, nan=1e5), a_min=-1e5, a_max=1e5)
38
39 # Predict the perfect Alpha
40 alpha = model.apply(params, jnp.expand_dims(stats, axis=0))
41 return jnp.squeeze(alpha)
42
43# 2. EXECUTION
44def smart_merge(model_a_path, model_b_path, brain_path, output_path):
45 print("Loading Alegbra-1.2 Brain...")
46 brain_weights = load_file(brain_path)
47 model = Alegbra1()
48
49 # Reconstruct Flax parameters
50 params_flat = {k: jnp.array(v) for k, v in brain_weights.items()}
51 from flax.traverse_util import unflatten_dict
52 params = unflatten_dict(params_flat, sep='.')
53
54 print("Loading SDXL Models...")
55 state_a = load_file(model_a_path)
56 state_b = load_file(model_b_path)
57 merged_dict = {}
58
59 keys = list(set(state_a.keys()).intersection(set(state_b.keys())))
60
61 print("Initiating Smart Fusion...")
62 for i, key in enumerate(keys):
63 ta = jnp.array(state_a[key])
64 tb = jnp.array(state_b[key])
65
66 if len(ta.shape) > 0:
67 alpha = float(get_alpha(model, params, ta, tb))
68 merged = ((1.0 - alpha) * ta) + (alpha * tb)
69 merged_dict[key] = np.array(merged, dtype=np.float16) # Compress to FP16
70 else:
71 merged_dict[key] = np.array((ta + tb) / 2.0, dtype=np.float16)
72
73 save_file(merged_dict, output_path)
74 print(f"Fusion Complete! Saved to {output_path}")
75
76# Run the function
77# smart_merge("model_A.safetensors", "model_B.safetensors", "Alegbra-1_v1-2_TPU.safetensors", "AlegbraFusion.safetensors")
78🏆 Proven Results
79Alegbra-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.