#!/bin/bash
# Detailed GGUF analysis: tensor names and shapes
/home/fabian/ComfyUI/venv/bin/python3 << 'PYEOF'
import gguf
import numpy as np

reader = gguf.GGUFReader("/home/fabian/ComfyUI/models/unet/z_image_turbo-Q5_K_S.gguf")

print("=== GGUF Tensors (first 30) ===")
for i, tensor in enumerate(reader.tensors[:30]):
    print(f"  {tensor.name}: shape={list(tensor.shape)} type={tensor.tensor_type}")

print(f"\nTotal tensors: {len(reader.tensors)}")

# Check max dim to determine model size
dims = set()
for t in reader.tensors:
    for s in t.shape:
        dims.add(int(s))

# Typical dim signatures:
# Lumina2 base: hidden=2304 (24 layers)
# ZImage: hidden=3840 (32 layers? depends on config)
print(f"\nDistinct tensor dimensions: {sorted(dims)[:20]}")

# Check if dim 3840 appears (Z-Image specific)
has_3840 = any(3840 in t.shape for t in reader.tensors)
has_2304 = any(2304 in t.shape for t in reader.tensors)
print(f"\nHas dim 3840 (Z-Image): {has_3840}")
print(f"Has dim 2304 (Lumina2 base): {has_2304}")

# Count layer numbers to determine depth
import re
layer_nums = set()
for t in reader.tensors:
    m = re.search(r'\.(\d+)\.', t.name)
    if m:
        layer_nums.add(int(m.group(1)))
if layer_nums:
    print(f"Layer range: {min(layer_nums)} to {max(layer_nums)} ({len(layer_nums)} layers)")
PYEOF

echo ""
echo "=== Disk space check ==="
df -h /home/fabian/ | tail -1

echo ""
echo "=== Available model size ==="
ls -lh /home/fabian/ComfyUI/models/unet/z_image_turbo-Q5_K_S.gguf
ls -lh /home/fabian/ComfyUI/models/text_encoders/gemma2_2b_lumina2.safetensors
ls -lh /home/fabian/ComfyUI/models/vae/ae.safetensors 2>/dev/null

echo ""
echo "=== RAM available ==="
free -h | head -2
