#!/bin/bash
# Check GGUF file for tokenizer data and check available tokenizer files

echo "=== GGUF metadata check ==="
cd /home/fabian/ComfyUI
/home/fabian/ComfyUI/venv/bin/python3 -c "
import gguf
reader = gguf.GGUFReader('models/diffusion_models/z_image_turbo-Q5_K_S.gguf')
print('GGUF fields:')
for key in list(reader.fields.keys())[:40]:
    field = reader.fields[key]
    tp = str(field.types)
    dl = len(field.data) if hasattr(field, 'data') else 0
    print(f'  {key}: types={tp} data_len={dl}')
"

echo ""
echo "=== Check for tokenizer.model files ==="
find /home/fabian/ComfyUI/comfy/text_encoders -name 'tokenizer*' -type f 2>/dev/null
echo ""

echo "=== Check llama_tokenizer ==="
ls -la /home/fabian/ComfyUI/comfy/text_encoders/llama_tokenizer/ 2>/dev/null || echo "No llama_tokenizer dir"

echo ""
echo "=== Check what z_image.py expects ==="
cat /home/fabian/ComfyUI/comfy/text_encoders/z_image.py 2>/dev/null || echo "No z_image.py"

echo ""
echo "=== Grep spiece_model in load functions ==="
grep -n 'spiece_model\|tokenizer_data\[' /home/fabian/ComfyUI/comfy/sd.py | head -20
