Spaces:
Paused
Paused
Update builder.sh
Browse files- builder.sh +108 -124
builder.sh
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
#!/usr/bin/env bash
|
| 2 |
set -euo pipefail
|
| 3 |
|
| 4 |
-
echo "🚀 Builder (FlashAttn LayerNorm + Apex + Q8) — runtime com GPU visível"
|
| 5 |
|
| 6 |
# ===== Config e diretórios =====
|
| 7 |
export SELF_HF_REPO_ID="${SELF_HF_REPO_ID:-euIaxs22/Aduc-sdr}" # Repo no HF para wheels
|
|
@@ -15,7 +15,7 @@ mkdir -p /app/wheels /app/cuda_cache "$HF_HOME" "$TORCH_HOME" /app/wheels/src
|
|
| 15 |
chmod -R 777 /app/wheels || true
|
| 16 |
export CUDA_CACHE_PATH="/app/cuda_cache"
|
| 17 |
|
| 18 |
-
#
|
| 19 |
if [ -f "/NGC-DL-CONTAINER-LICENSE" ]; then
|
| 20 |
cp -f /NGC-DL-CONTAINER-LICENSE /app/wheels/NGC-DL-CONTAINER-LICENSE || true
|
| 21 |
fi
|
|
@@ -49,16 +49,23 @@ echo "[env] PY_TAG=${PY_TAG} TORCH_VER=${TORCH_VER} CU_TAG=${CU_TAG}"
|
|
| 49 |
# CHECKERS
|
| 50 |
# ============================================================================
|
| 51 |
|
| 52 |
-
|
|
|
|
| 53 |
python - <<'PY'
|
| 54 |
-
import importlib
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
"
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
raise SystemExit(0 if ok else 1)
|
| 63 |
PY
|
| 64 |
}
|
|
@@ -66,7 +73,7 @@ PY
|
|
| 66 |
check_apex () {
|
| 67 |
python - <<'PY'
|
| 68 |
try:
|
| 69 |
-
from apex.normalization import FusedLayerNorm
|
| 70 |
import importlib; importlib.import_module("fused_layer_norm_cuda")
|
| 71 |
ok = True
|
| 72 |
except Exception:
|
|
@@ -87,13 +94,12 @@ PY
|
|
| 87 |
# DOWNLOAD DO HUB (GENÉRICO)
|
| 88 |
# ============================================================================
|
| 89 |
|
| 90 |
-
# Instala uma wheel do HF por
|
| 91 |
-
# Uso: install_from_hf_by_prefix <prefixo>
|
| 92 |
install_from_hf_by_prefix () {
|
| 93 |
local PREFIX="$1"
|
| 94 |
echo "[hub] Procurando wheels '${PREFIX}-*.whl' em ${SELF_HF_REPO_ID} com tags ${PY_TAG}/${CU_TAG}"
|
| 95 |
python - "$PREFIX" "$PY_TAG" "$CU_TAG" <<'PY' || exit 0
|
| 96 |
-
import os, sys
|
| 97 |
from huggingface_hub import HfApi, hf_hub_download, HfFolder
|
| 98 |
|
| 99 |
prefix, py_tag, cu_tag = sys.argv[1], sys.argv[2], sys.argv[3]
|
|
@@ -104,18 +110,14 @@ try:
|
|
| 104 |
except Exception:
|
| 105 |
raise SystemExit(0)
|
| 106 |
|
| 107 |
-
def
|
| 108 |
-
|
| 109 |
-
if py_tag not in name:
|
| 110 |
-
return False
|
| 111 |
-
return True
|
| 112 |
|
| 113 |
-
cands = [f for f in files if
|
| 114 |
pref = [f for f in cands if cu_tag and cu_tag in f] or cands
|
| 115 |
if not pref:
|
| 116 |
raise SystemExit(0)
|
| 117 |
|
| 118 |
-
# Seleciona o "maior" por ordenação lexicográfica como heurística de versão/compat
|
| 119 |
target = sorted(pref, reverse=True)[0]
|
| 120 |
print(target)
|
| 121 |
path = hf_hub_download(repo_id=repo, filename=target, repo_type="model", local_dir="/app/wheels")
|
|
@@ -123,9 +125,9 @@ print(path)
|
|
| 123 |
PY
|
| 124 |
}
|
| 125 |
|
| 126 |
-
# Instala
|
| 127 |
-
|
| 128 |
-
echo "[hub] Procurando wheels
|
| 129 |
python - "$PY_TAG" "$CU_TAG" <<'PY' || exit 0
|
| 130 |
import os, sys, re
|
| 131 |
from huggingface_hub import HfApi, hf_hub_download, HfFolder
|
|
@@ -138,15 +140,13 @@ try:
|
|
| 138 |
except Exception:
|
| 139 |
raise SystemExit(0)
|
| 140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
def ok(fn: str) -> bool:
|
| 142 |
name = fn.rsplit("/",1)[-1]
|
| 143 |
-
if not name.endswith(".whl"): return False
|
| 144 |
if py_tag not in name: return False
|
| 145 |
-
# Padrões comuns de empacotamento
|
| 146 |
-
pats = [
|
| 147 |
-
r"^flash[_-]?attn[_-]?.*layer[_-]?norm-",
|
| 148 |
-
r"^dropout[_-]?layer[_-]?norm-",
|
| 149 |
-
]
|
| 150 |
return any(re.search(p, name, flags=re.I) for p in pats)
|
| 151 |
|
| 152 |
cands = [f for f in files if ok(f)]
|
|
@@ -165,11 +165,29 @@ PY
|
|
| 165 |
# BUILDERS
|
| 166 |
# ============================================================================
|
| 167 |
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
local SRC="/app/wheels/src/flash-attn"
|
| 170 |
echo "[build] Preparando fonte FlashAttention (layer_norm) em ${SRC}"
|
| 171 |
-
|
| 172 |
-
# Sync/clone
|
| 173 |
if [ -d "$SRC/.git" ]; then
|
| 174 |
git -C "$SRC" fetch --all -p || true
|
| 175 |
git -C "$SRC" reset --hard origin/main || true
|
|
@@ -179,41 +197,49 @@ build_flashln () {
|
|
| 179 |
git clone --depth 1 https://github.com/Dao-AILab/flash-attention "$SRC"
|
| 180 |
fi
|
| 181 |
|
| 182 |
-
#
|
| 183 |
export TORCH_CUDA_ARCH_LIST="$(python - <<'PY'
|
| 184 |
import torch
|
| 185 |
try:
|
| 186 |
-
|
| 187 |
-
print(
|
| 188 |
except Exception:
|
| 189 |
-
# fallback
|
| 190 |
-
print("8.9")
|
| 191 |
PY
|
| 192 |
)"
|
| 193 |
echo "[build] TORCH_CUDA_ARCH_LIST=${TORCH_CUDA_ARCH_LIST}"
|
| 194 |
|
| 195 |
-
# Compila apenas o submódulo csrc/layer_norm para wheel
|
| 196 |
pushd "$SRC/csrc/layer_norm" >/dev/null
|
| 197 |
export MAX_JOBS="${MAX_JOBS:-90}"
|
|
|
|
| 198 |
python -m pip wheel -v --no-build-isolation --no-deps . -w /app/wheels || true
|
| 199 |
popd >/dev/null
|
| 200 |
|
| 201 |
-
# Instala a wheel
|
| 202 |
local W="$(ls -t /app/wheels/*flash*attn*layer*norm*-*.whl 2>/dev/null | head -n1 || true)"
|
| 203 |
if [ -z "${W}" ]; then
|
| 204 |
W="$(ls -t /app/wheels/*dropout*layer*norm*-*.whl 2>/dev/null | head -n1 || true)"
|
| 205 |
fi
|
| 206 |
if [ -z "${W}" ]; then
|
| 207 |
-
# fallback para qualquer
|
| 208 |
W="$(ls -t /app/wheels/*.whl 2>/dev/null | head -n1 || true)"
|
| 209 |
fi
|
|
|
|
| 210 |
if [ -n "${W}" ]; then
|
| 211 |
python -m pip install -v -U --no-deps "${W}" || true
|
| 212 |
-
echo "[build]
|
| 213 |
else
|
| 214 |
-
echo "[build] Nenhuma wheel gerada; instalando do source (
|
| 215 |
python -m pip install -v --no-build-isolation "$SRC/csrc/layer_norm" || true
|
| 216 |
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
}
|
| 218 |
|
| 219 |
build_apex () {
|
|
@@ -235,7 +261,7 @@ build_apex () {
|
|
| 235 |
python -m pip install -v -U --no-deps "${W}" || true
|
| 236 |
echo "[build] Apex instalado da wheel recém-compilada: ${W}"
|
| 237 |
else
|
| 238 |
-
echo "[build] Nenhuma wheel Apex gerada; instalando do source
|
| 239 |
python -m pip install -v --no-build-isolation "$SRC" || true
|
| 240 |
fi
|
| 241 |
}
|
|
@@ -255,94 +281,52 @@ build_q8 () {
|
|
| 255 |
python -m pip install -v -U --no-deps "${W}" || true
|
| 256 |
echo "[build] Q8 instalado da wheel recém-compilada: ${W}"
|
| 257 |
else
|
| 258 |
-
echo "[build] Nenhuma wheel q8_kernels gerada; instalando do source
|
| 259 |
python -m pip install -v --no-build-isolation "$SRC" || true
|
| 260 |
fi
|
| 261 |
}
|
| 262 |
|
| 263 |
# ============================================================================
|
| 264 |
-
#
|
| 265 |
# ============================================================================
|
| 266 |
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
echo "[
|
| 277 |
-
|
| 278 |
-
if
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
python -m pip install -v -U --no-build-isolation "${WHEEL_PATH}" || true
|
| 282 |
-
if ${CHECK_FN}; then
|
| 283 |
-
echo "[flow] ${PKG}: sucesso via Hub (${WHEEL_PATH})"
|
| 284 |
-
return 0
|
| 285 |
-
else
|
| 286 |
-
echo "[flow] ${PKG}: import falhou após wheel do Hub; compilando"
|
| 287 |
-
fi
|
| 288 |
-
else
|
| 289 |
-
echo "[hub] Nenhuma wheel compatível encontrada para ${PKG}"
|
| 290 |
fi
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
return 0
|
| 296 |
-
fi
|
| 297 |
-
echo "[flow] ${PKG}: falhou após build; seguindo"
|
| 298 |
-
return 1
|
| 299 |
-
}
|
| 300 |
-
|
| 301 |
-
ensure_flashln () {
|
| 302 |
-
echo "[flow] === flash_attn_layer_norm ==="
|
| 303 |
-
if check_flashln; then
|
| 304 |
-
echo "[flow] FlashAttn LayerNorm: já instalado (import OK)"
|
| 305 |
-
return 0
|
| 306 |
-
fi
|
| 307 |
-
echo "[flow] FlashAttn LayerNorm: tentando wheel do Hub (${SELF_HF_REPO_ID})"
|
| 308 |
-
HF_OUT="$(install_flashln_from_hf || true)"
|
| 309 |
-
if [ -n "${HF_OUT:-}" ]; then
|
| 310 |
-
WHEEL_PATH="$(printf "%s\n" "${HF_OUT}" | tail -n1)"
|
| 311 |
-
echo "[hub] Baixado: ${WHEEL_PATH}"
|
| 312 |
-
python -m pip install -v -U --no-build-isolation "${WHEEL_PATH}" || true
|
| 313 |
-
if check_flashln; then
|
| 314 |
-
echo "[flow] FlashAttn LayerNorm: sucesso via Hub (${WHEEL_PATH})"
|
| 315 |
-
return 0
|
| 316 |
-
else
|
| 317 |
-
echo "[flow] FlashAttn LayerNorm: import falhou após wheel do Hub; compilando"
|
| 318 |
-
fi
|
| 319 |
-
else
|
| 320 |
-
echo "[hub] Nenhuma wheel compatível encontrada para FlashAttn LayerNorm"
|
| 321 |
-
fi
|
| 322 |
-
echo "[flow] FlashAttn LayerNorm: compilando (fallback)"
|
| 323 |
-
build_flashln
|
| 324 |
-
if check_flashln; then
|
| 325 |
-
echo "[flow] FlashAttn LayerNorm: sucesso após compilação"
|
| 326 |
-
return 0
|
| 327 |
-
fi
|
| 328 |
-
echo "[flow] FlashAttn LayerNorm: falhou após build; seguindo"
|
| 329 |
-
return 1
|
| 330 |
-
}
|
| 331 |
-
|
| 332 |
-
# ============================================================================
|
| 333 |
-
# EXECUÇÃO
|
| 334 |
-
# ============================================================================
|
| 335 |
-
|
| 336 |
-
# 1) FlashAttention LayerNorm (novo cache em wheel no HF)
|
| 337 |
-
ensure_flashln || true
|
| 338 |
-
|
| 339 |
-
# 2) Apex (mantém pipeline existente)
|
| 340 |
-
ensure_pkg "apex" check_apex build_apex || true
|
| 341 |
-
|
| 342 |
-
# 3) Q8 kernels (opcional)
|
| 343 |
-
# ensure_pkg "q8_kernels" check_q8 build_q8 || true
|
| 344 |
|
| 345 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
python - <<'PY'
|
| 347 |
import os
|
| 348 |
from huggingface_hub import HfApi, HfFolder
|
|
|
|
| 1 |
#!/usr/bin/env bash
|
| 2 |
set -euo pipefail
|
| 3 |
|
| 4 |
+
echo "🚀 Builder (FlashAttn LayerNorm extra + Apex + Q8) — runtime com GPU visível"
|
| 5 |
|
| 6 |
# ===== Config e diretórios =====
|
| 7 |
export SELF_HF_REPO_ID="${SELF_HF_REPO_ID:-euIaxs22/Aduc-sdr}" # Repo no HF para wheels
|
|
|
|
| 15 |
chmod -R 777 /app/wheels || true
|
| 16 |
export CUDA_CACHE_PATH="/app/cuda_cache"
|
| 17 |
|
| 18 |
+
# Preserva licença NGC (se existir)
|
| 19 |
if [ -f "/NGC-DL-CONTAINER-LICENSE" ]; then
|
| 20 |
cp -f /NGC-DL-CONTAINER-LICENSE /app/wheels/NGC-DL-CONTAINER-LICENSE || true
|
| 21 |
fi
|
|
|
|
| 49 |
# CHECKERS
|
| 50 |
# ============================================================================
|
| 51 |
|
| 52 |
+
# Checa especificamente o módulo nativo requerido pelo layer_norm (sem checar 'flash-attn' geral)
|
| 53 |
+
check_flash_layer_norm_bin () {
|
| 54 |
python - <<'PY'
|
| 55 |
+
import importlib
|
| 56 |
+
ok = False
|
| 57 |
+
# extensões conhecidas produzidas por csrc/layer_norm
|
| 58 |
+
for name in [
|
| 59 |
+
"dropout_layer_norm", # nome do módulo nativo
|
| 60 |
+
"flash_attn.ops.layer_norm", # wrapper python que usa o nativo
|
| 61 |
+
"flash_attn.ops.rms_norm", # pode depender do mesmo backend em alguns empacotamentos
|
| 62 |
+
]:
|
| 63 |
+
try:
|
| 64 |
+
importlib.import_module(name)
|
| 65 |
+
ok = True
|
| 66 |
+
break
|
| 67 |
+
except Exception:
|
| 68 |
+
pass
|
| 69 |
raise SystemExit(0 if ok else 1)
|
| 70 |
PY
|
| 71 |
}
|
|
|
|
| 73 |
check_apex () {
|
| 74 |
python - <<'PY'
|
| 75 |
try:
|
| 76 |
+
from apex.normalization import FusedLayerNorm
|
| 77 |
import importlib; importlib.import_module("fused_layer_norm_cuda")
|
| 78 |
ok = True
|
| 79 |
except Exception:
|
|
|
|
| 94 |
# DOWNLOAD DO HUB (GENÉRICO)
|
| 95 |
# ============================================================================
|
| 96 |
|
| 97 |
+
# Instala uma wheel do HF por prefixo simples (ex.: apex-, q8_kernels-)
|
|
|
|
| 98 |
install_from_hf_by_prefix () {
|
| 99 |
local PREFIX="$1"
|
| 100 |
echo "[hub] Procurando wheels '${PREFIX}-*.whl' em ${SELF_HF_REPO_ID} com tags ${PY_TAG}/${CU_TAG}"
|
| 101 |
python - "$PREFIX" "$PY_TAG" "$CU_TAG" <<'PY' || exit 0
|
| 102 |
+
import os, sys
|
| 103 |
from huggingface_hub import HfApi, hf_hub_download, HfFolder
|
| 104 |
|
| 105 |
prefix, py_tag, cu_tag = sys.argv[1], sys.argv[2], sys.argv[3]
|
|
|
|
| 110 |
except Exception:
|
| 111 |
raise SystemExit(0)
|
| 112 |
|
| 113 |
+
def match(name: str) -> bool:
|
| 114 |
+
return name.endswith(".whl") and name.rsplit("/",1)[-1].startswith(prefix + "-") and (py_tag in name)
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
+
cands = [f for f in files if match(f)]
|
| 117 |
pref = [f for f in cands if cu_tag and cu_tag in f] or cands
|
| 118 |
if not pref:
|
| 119 |
raise SystemExit(0)
|
| 120 |
|
|
|
|
| 121 |
target = sorted(pref, reverse=True)[0]
|
| 122 |
print(target)
|
| 123 |
path = hf_hub_download(repo_id=repo, filename=target, repo_type="model", local_dir="/app/wheels")
|
|
|
|
| 125 |
PY
|
| 126 |
}
|
| 127 |
|
| 128 |
+
# Instala wheels do submódulo layer_norm aceitando variantes de nome
|
| 129 |
+
install_flash_layer_norm_from_hf () {
|
| 130 |
+
echo "[hub] Procurando wheels FlashAttention LayerNorm em ${SELF_HF_REPO_ID}"
|
| 131 |
python - "$PY_TAG" "$CU_TAG" <<'PY' || exit 0
|
| 132 |
import os, sys, re
|
| 133 |
from huggingface_hub import HfApi, hf_hub_download, HfFolder
|
|
|
|
| 140 |
except Exception:
|
| 141 |
raise SystemExit(0)
|
| 142 |
|
| 143 |
+
pats = [
|
| 144 |
+
r"^flash[_-]?attn[_-]?.*layer[_-]?norm-.*\.whl$",
|
| 145 |
+
r"^dropout[_-]?layer[_-]?norm-.*\.whl$",
|
| 146 |
+
]
|
| 147 |
def ok(fn: str) -> bool:
|
| 148 |
name = fn.rsplit("/",1)[-1]
|
|
|
|
| 149 |
if py_tag not in name: return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
return any(re.search(p, name, flags=re.I) for p in pats)
|
| 151 |
|
| 152 |
cands = [f for f in files if ok(f)]
|
|
|
|
| 165 |
# BUILDERS
|
| 166 |
# ============================================================================
|
| 167 |
|
| 168 |
+
# Passo extra: SIEMPRE tenta instalar o submódulo layer_norm via wheel do HF;
|
| 169 |
+
# se não houver wheel compatível, compila a partir de csrc/layer_norm e gera wheel.
|
| 170 |
+
build_or_install_flash_layer_norm () {
|
| 171 |
+
echo "[flow] === FlashAttn LayerNorm (passo extra) ==="
|
| 172 |
+
|
| 173 |
+
# 1) Tentar instalar wheel do HF primeiro (evita recompilar)
|
| 174 |
+
HF_OUT="$(install_flash_layer_norm_from_hf || true)"
|
| 175 |
+
if [ -n "${HF_OUT:-}" ]; then
|
| 176 |
+
WHEEL_PATH="$(printf "%s\n" "${HF_OUT}" | tail -n1)"
|
| 177 |
+
echo "[hub] Baixado: ${WHEEL_PATH}"
|
| 178 |
+
python -m pip install -v -U --no-build-isolation --no-deps "${WHEEL_PATH}" || true
|
| 179 |
+
if check_flash_layer_norm_bin; then
|
| 180 |
+
echo "[flow] FlashAttn LayerNorm: OK via wheel do Hub"
|
| 181 |
+
return 0
|
| 182 |
+
fi
|
| 183 |
+
echo "[flow] Wheel do Hub não resolveu import; seguirá com build"
|
| 184 |
+
else
|
| 185 |
+
echo "[hub] Nenhuma wheel compatível encontrada para FlashAttn LayerNorm"
|
| 186 |
+
fi
|
| 187 |
+
|
| 188 |
+
# 2) Build from source do submódulo csrc/layer_norm -> wheel
|
| 189 |
local SRC="/app/wheels/src/flash-attn"
|
| 190 |
echo "[build] Preparando fonte FlashAttention (layer_norm) em ${SRC}"
|
|
|
|
|
|
|
| 191 |
if [ -d "$SRC/.git" ]; then
|
| 192 |
git -C "$SRC" fetch --all -p || true
|
| 193 |
git -C "$SRC" reset --hard origin/main || true
|
|
|
|
| 197 |
git clone --depth 1 https://github.com/Dao-AILab/flash-attention "$SRC"
|
| 198 |
fi
|
| 199 |
|
| 200 |
+
# Define CC alvo a partir da GPU ativa (reduz tempo/ruído de build)
|
| 201 |
export TORCH_CUDA_ARCH_LIST="$(python - <<'PY'
|
| 202 |
import torch
|
| 203 |
try:
|
| 204 |
+
cc = "%d.%d" % torch.cuda.get_device_capability(0)
|
| 205 |
+
print(cc)
|
| 206 |
except Exception:
|
| 207 |
+
print("8.9") # fallback p/ Ada (L40S) caso build sem GPU visível
|
|
|
|
| 208 |
PY
|
| 209 |
)"
|
| 210 |
echo "[build] TORCH_CUDA_ARCH_LIST=${TORCH_CUDA_ARCH_LIST}"
|
| 211 |
|
|
|
|
| 212 |
pushd "$SRC/csrc/layer_norm" >/dev/null
|
| 213 |
export MAX_JOBS="${MAX_JOBS:-90}"
|
| 214 |
+
# Gera wheel reutilizável
|
| 215 |
python -m pip wheel -v --no-build-isolation --no-deps . -w /app/wheels || true
|
| 216 |
popd >/dev/null
|
| 217 |
|
| 218 |
+
# Instala a wheel gerada
|
| 219 |
local W="$(ls -t /app/wheels/*flash*attn*layer*norm*-*.whl 2>/dev/null | head -n1 || true)"
|
| 220 |
if [ -z "${W}" ]; then
|
| 221 |
W="$(ls -t /app/wheels/*dropout*layer*norm*-*.whl 2>/dev/null | head -n1 || true)"
|
| 222 |
fi
|
| 223 |
if [ -z "${W}" ]; then
|
| 224 |
+
# fallback para qualquer .whl recém gerado
|
| 225 |
W="$(ls -t /app/wheels/*.whl 2>/dev/null | head -n1 || true)"
|
| 226 |
fi
|
| 227 |
+
|
| 228 |
if [ -n "${W}" ]; then
|
| 229 |
python -m pip install -v -U --no-deps "${W}" || true
|
| 230 |
+
echo "[build] FlashAttn LayerNorm instalado da wheel: ${W}"
|
| 231 |
else
|
| 232 |
+
echo "[build] Nenhuma wheel gerada; instalando direto do source (último recurso)"
|
| 233 |
python -m pip install -v --no-build-isolation "$SRC/csrc/layer_norm" || true
|
| 234 |
fi
|
| 235 |
+
|
| 236 |
+
# Checagem final do binário
|
| 237 |
+
if check_flash_layer_norm_bin; then
|
| 238 |
+
echo "[flow] FlashAttn LayerNorm: import OK após build"
|
| 239 |
+
return 0
|
| 240 |
+
fi
|
| 241 |
+
echo "[flow] FlashAttn LayerNorm: falhou import após build"
|
| 242 |
+
return 1
|
| 243 |
}
|
| 244 |
|
| 245 |
build_apex () {
|
|
|
|
| 261 |
python -m pip install -v -U --no-deps "${W}" || true
|
| 262 |
echo "[build] Apex instalado da wheel recém-compilada: ${W}"
|
| 263 |
else
|
| 264 |
+
echo "[build] Nenhuma wheel Apex gerada; instalando do source"
|
| 265 |
python -m pip install -v --no-build-isolation "$SRC" || true
|
| 266 |
fi
|
| 267 |
}
|
|
|
|
| 281 |
python -m pip install -v -U --no-deps "${W}" || true
|
| 282 |
echo "[build] Q8 instalado da wheel recém-compilada: ${W}"
|
| 283 |
else
|
| 284 |
+
echo "[build] Nenhuma wheel q8_kernels gerada; instalando do source"
|
| 285 |
python -m pip install -v --no-build-isolation "$SRC" || true
|
| 286 |
fi
|
| 287 |
}
|
| 288 |
|
| 289 |
# ============================================================================
|
| 290 |
+
# EXECUÇÃO
|
| 291 |
# ============================================================================
|
| 292 |
|
| 293 |
+
# Passo adicional SEM depender de "flash-attn" já instalado: trata somente o layer_norm
|
| 294 |
+
build_or_install_flash_layer_norm || true
|
| 295 |
+
|
| 296 |
+
# Apex (mantido)
|
| 297 |
+
# Tenta primeiro via wheel no HF e, se não houver, compila e instala em wheel
|
| 298 |
+
echo "[flow] === apex ==="
|
| 299 |
+
HF_OUT="$(install_from_hf_by_prefix "apex" || true)"
|
| 300 |
+
if [ -n "${HF_OUT:-}" ]; then
|
| 301 |
+
WHEEL_PATH="$(printf "%s\n" "${HF_OUT}" | tail -n1)"
|
| 302 |
+
echo "[hub] Baixado: ${WHEEL_PATH}"
|
| 303 |
+
python -m pip install -v -U --no-build-isolation "${WHEEL_PATH}" || true
|
| 304 |
+
if ! check_apex; then
|
| 305 |
+
echo "[flow] apex: import falhou após wheel; compilando"
|
| 306 |
+
build_apex || true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
fi
|
| 308 |
+
else
|
| 309 |
+
echo "[hub] Nenhuma wheel apex compatível; compilando"
|
| 310 |
+
build_apex || true
|
| 311 |
+
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
|
| 313 |
+
# Q8 (opcional)
|
| 314 |
+
# echo "[flow] === q8_kernels ==="
|
| 315 |
+
# HF_OUT="$(install_from_hf_by_prefix "q8_kernels" || true)"
|
| 316 |
+
# if [ -n "${HF_OUT:-}" ]; then
|
| 317 |
+
# WHEEL_PATH="$(printf "%s\n" "${HF_OUT}" | tail -n1)"
|
| 318 |
+
# echo "[hub] Baixado: ${WHEEL_PATH}"
|
| 319 |
+
# python -m pip install -v -U --no-build-isolation "${WHEEL_PATH}" || true
|
| 320 |
+
# if ! check_q8; then
|
| 321 |
+
# echo "[flow] q8_kernels: import falhou após wheel; compilando"
|
| 322 |
+
# build_q8 || true
|
| 323 |
+
# fi
|
| 324 |
+
# else
|
| 325 |
+
# echo "[hub] Nenhuma wheel q8_kernels compatível; compilando"
|
| 326 |
+
# build_q8 || true
|
| 327 |
+
# fi
|
| 328 |
+
|
| 329 |
+
# Upload de wheels produzidas para o HF (cache cross-restarts)
|
| 330 |
python - <<'PY'
|
| 331 |
import os
|
| 332 |
from huggingface_hub import HfApi, HfFolder
|