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|
+
export PYTHONDONTWRITEBYTECODE=1
|
| 5 |
+
export CUDA_VISIBLE_DEVICES=0
|
| 6 |
+
export WORK=/dev/shm/eval
|
| 7 |
+
|
| 8 |
+
log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"; }
|
| 9 |
+
|
| 10 |
+
log "============================================"
|
| 11 |
+
log " Setup: Polish LLM Eval for QuIP# Bielik"
|
| 12 |
+
log "============================================"
|
| 13 |
+
|
| 14 |
+
mkdir -p "$WORK"
|
| 15 |
+
cd "$WORK"
|
| 16 |
+
|
| 17 |
+
# 1. HF login first (needed for private model download)
|
| 18 |
+
log "HuggingFace login..."
|
| 19 |
+
python -c "
|
| 20 |
+
from huggingface_hub import login
|
| 21 |
+
login(token='HF_TOKEN_REDACTED')
|
| 22 |
+
print('Login OK')
|
| 23 |
+
"
|
| 24 |
+
|
| 25 |
+
# 2. Clone speakleash lm-eval fork with Polish tasks
|
| 26 |
+
log "Cloning speakleash/lm-evaluation-harness (polish3 branch)..."
|
| 27 |
+
if [ ! -d "$WORK/lm-evaluation-harness" ]; then
|
| 28 |
+
git clone https://github.com/speakleash/lm-evaluation-harness.git -b polish3
|
| 29 |
+
fi
|
| 30 |
+
cd "$WORK/lm-evaluation-harness"
|
| 31 |
+
pip install -e . 2>&1 | tail -5
|
| 32 |
+
log "lm-eval installed"
|
| 33 |
+
|
| 34 |
+
# 3. Clone quip-sharp for model loading
|
| 35 |
+
cd "$WORK"
|
| 36 |
+
if [ ! -d "$WORK/quip-sharp" ]; then
|
| 37 |
+
git clone https://github.com/Cornell-RelaxML/quip-sharp.git
|
| 38 |
+
fi
|
| 39 |
+
cd "$WORK/quip-sharp"
|
| 40 |
+
|
| 41 |
+
# 4. Build CUDA kernels
|
| 42 |
+
log "Building quiptools CUDA kernels..."
|
| 43 |
+
cd quiptools && python setup.py install 2>&1 | tail -5 && cd ..
|
| 44 |
+
log "quiptools built"
|
| 45 |
+
|
| 46 |
+
# 5. Install deps
|
| 47 |
+
pip install glog primefac protobuf sentencepiece 2>&1 | tail -3
|
| 48 |
+
|
| 49 |
+
# 6. Apply patches
|
| 50 |
+
log "Applying quip-sharp patches..."
|
| 51 |
+
|
| 52 |
+
# torch.load compat for PyTorch 2.10+
|
| 53 |
+
python -c "
|
| 54 |
+
for f in ['lib/utils/unsafe_import.py', 'eval/eval_zeroshot.py']:
|
| 55 |
+
try:
|
| 56 |
+
path = '$WORK/quip-sharp/' + f
|
| 57 |
+
with open(path, 'r') as fh:
|
| 58 |
+
c = fh.read()
|
| 59 |
+
if 'weights_only' not in c and 'torch.load' in c:
|
| 60 |
+
c = c.replace('import torch\n', 'import torch\n_orig_load = torch.load\ndef _compat_load(*a, **kw):\n kw.setdefault(\"weights_only\", False)\n return _orig_load(*a, **kw)\ntorch.load = _compat_load\n', 1)
|
| 61 |
+
with open(path, 'w') as fh:
|
| 62 |
+
fh.write(c)
|
| 63 |
+
print(f'Patched {f}')
|
| 64 |
+
except FileNotFoundError:
|
| 65 |
+
pass
|
| 66 |
+
"
|
| 67 |
+
|
| 68 |
+
# fast_hadamard_transform fallback
|
| 69 |
+
python -c "
|
| 70 |
+
path = '$WORK/quip-sharp/lib/utils/matmul_had.py'
|
| 71 |
+
with open(path, 'r') as f:
|
| 72 |
+
content = f.read()
|
| 73 |
+
if content.startswith('import fast_hadamard_transform'):
|
| 74 |
+
content = 'try:\n import fast_hadamard_transform\n HAS_FAST_HAD = True\nexcept ImportError:\n HAS_FAST_HAD = False\n' + content.split('\n', 1)[1]
|
| 75 |
+
with open(path, 'w') as f:
|
| 76 |
+
f.write(content)
|
| 77 |
+
print('matmul_had.py patched')
|
| 78 |
+
"
|
| 79 |
+
|
| 80 |
+
# hadamard fallback implementation
|
| 81 |
+
python -c "
|
| 82 |
+
path = '$WORK/quip-sharp/lib/utils/matmul_had.py'
|
| 83 |
+
with open(path, 'r') as f:
|
| 84 |
+
c = f.read()
|
| 85 |
+
if 'HAS_FAST_HAD' in c and 'Walsh-Hadamard' not in c:
|
| 86 |
+
old = 'return fast_hadamard_transform.hadamard_transform(x, scale)'
|
| 87 |
+
new = '''if HAS_FAST_HAD:
|
| 88 |
+
return fast_hadamard_transform.hadamard_transform(x, scale)
|
| 89 |
+
else:
|
| 90 |
+
# Pure PyTorch Walsh-Hadamard fallback
|
| 91 |
+
n = x.shape[-1]
|
| 92 |
+
orig_shape = x.shape
|
| 93 |
+
x = x.contiguous().view(-1, n)
|
| 94 |
+
h = 1
|
| 95 |
+
while h < n:
|
| 96 |
+
x = x.view(-1, n // (2 * h), 2, h)
|
| 97 |
+
a = x[:, :, 0, :] + x[:, :, 1, :]
|
| 98 |
+
b = x[:, :, 0, :] - x[:, :, 1, :]
|
| 99 |
+
x = torch.stack([a, b], dim=2).view(-1, n)
|
| 100 |
+
h *= 2
|
| 101 |
+
return (x * scale).view(orig_shape)'''
|
| 102 |
+
if old in c:
|
| 103 |
+
c = c.replace(old, new)
|
| 104 |
+
with open(path, 'w') as f:
|
| 105 |
+
f.write(c)
|
| 106 |
+
print('hadamard fallback added')
|
| 107 |
+
"
|
| 108 |
+
|
| 109 |
+
# 7. Download QuIP# model from HuggingFace
|
| 110 |
+
log "Downloading QuIP# model..."
|
| 111 |
+
mkdir -p "$WORK/model"
|
| 112 |
+
python -c "
|
| 113 |
+
from huggingface_hub import snapshot_download
|
| 114 |
+
path = snapshot_download('Jakubrd4/bielik-q2-variant-a', local_dir='$WORK/model')
|
| 115 |
+
print(f'Model downloaded to: {path}')
|
| 116 |
+
"
|
| 117 |
+
log "Model downloaded"
|
| 118 |
+
|
| 119 |
+
# 8. Download tokenizer (base model)
|
| 120 |
+
log "Pre-downloading tokenizer..."
|
| 121 |
+
python -c "
|
| 122 |
+
from transformers import AutoTokenizer
|
| 123 |
+
tok = AutoTokenizer.from_pretrained('speakleash/Bielik-11B-v2.3-Instruct')
|
| 124 |
+
print(f'Tokenizer loaded: {tok.name_or_path}, vocab_size={tok.vocab_size}')
|
| 125 |
+
"
|
| 126 |
+
|
| 127 |
+
# 9. List available Polish tasks
|
| 128 |
+
log "Available Polish tasks:"
|
| 129 |
+
cd "$WORK/lm-evaluation-harness"
|
| 130 |
+
python -c "
|
| 131 |
+
from lm_eval import tasks
|
| 132 |
+
mgr = tasks.TaskManager()
|
| 133 |
+
polish = [t for t in mgr.all_tasks if 'polish' in t.lower() or 'polemo' in t.lower()]
|
| 134 |
+
for t in sorted(polish):
|
| 135 |
+
print(f' {t}')
|
| 136 |
+
print(f'Total: {len(polish)} Polish tasks')
|
| 137 |
+
" 2>/dev/null || echo "Task listing skipped"
|
| 138 |
+
|
| 139 |
+
log "============================================"
|
| 140 |
+
log " Setup complete! Ready for eval."
|
| 141 |
+
log "============================================"
|