File size: 3,278 Bytes
f9bc0c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env bash
# Remote (khalti-t4) environment setup + probe. Run FIRST after cloning the bundle.
# Usage: bash tools/exp/remote_setup.sh [--target PATH] [--torch-cpu]
#
# --target: pip --target deps dir (default $REPO/.deps) — matches local practice
#           when the box forbids venvs; prepend it to PYTHONPATH (the run sheets
#           and every tools/exp script already do this).
# --torch-cpu: CPU-only torch wheel (default: CUDA wheel — needs nvidia-smi present).
#
# Both flags may be combined.  Everything is installed with --upgrade so a
# re-run repairs a partially-failed install.
set -euo pipefail

REPO=$(cd "$(dirname "$0")/../.." && pwd)
DEPS="$REPO/.deps"
TORCH_INDEX=""
while [[ $# -gt 0 ]]; do
  case "$1" in
    --target) DEPS="$2"; shift 2 ;;
    --torch-cpu) TORCH_INDEX="--index-url https://download.pytorch.org/whl/cpu"; shift ;;
    *) echo "unknown arg $1"; exit 1 ;;
  esac
done

mkdir -p "$DEPS" "$REPO/results"
cd "$REPO"   # callable from anywhere (probe + selfcheck paths are repo-relative)

echo "== probes =="
python3 -V || true
python3 -m pip --version || pip --version || true
nproc || true
free -h || true
df -h "$REPO" | tail -1 || true
nvidia-smi || echo "(no nvidia-smi — CPU-only box?)"

echo "== pip install into $DEPS =="
python3 -m pip install --quiet --target "$DEPS" --upgrade \
    numpy opencv-python-headless pillow onnx onnxruntime \
    safetensors pypdfium2 huggingface_hub
python3 -m pip install --quiet --target "$DEPS" --upgrade $TORCH_INDEX torch

echo "== import check + probe.json =="
REPO="$REPO" PYTHONPATH="$DEPS:$REPO/indra:$REPO/tools" python3 - <<'EOF'
import json, os, sys, pathlib
import numpy as np, cv2, PIL
probe = {"python": sys.version.split()[0], "numpy": np.__version__,
         "cv2": cv2.__version__, "pillow": PIL.__version__}
try:
    import torch
    probe["torch"] = torch.__version__
    probe["cuda"] = torch.cuda.is_available()
    probe["cuda_device"] = torch.cuda.get_device_name(0) if probe["cuda"] else None
    probe["torch_amp_gradscaler"] = hasattr(torch, "amp")
except Exception as ex:
    probe["torch"] = f"IMPORT FAIL: {ex}"
try:
    import onnxruntime as ort
    probe["onnxruntime"] = ort.__version__
    probe["ort_providers"] = ort.get_available_providers()
except Exception as ex:
    probe["onnxruntime"] = f"IMPORT FAIL: {ex}"
try:
    import onnx
    probe["onnx"] = onnx.__version__
except Exception as ex:
    probe["onnx"] = f"IMPORT FAIL: {ex}"
from indra_ocr.vocab import Vocab
probe["indra_vocab_classes"] = Vocab.multi().n_classes
repo = pathlib.Path(os.environ["REPO"])
out = repo / "results" / "probe.json"
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text(json.dumps(probe, indent=1) + "\n")
print(json.dumps(probe, indent=1))
print(f"wrote {out}")
EOF

echo "== sanity: recognizer selfcheck (needs safetensors) =="
PYTHONPATH="$DEPS:$REPO/indra:$REPO/tools" python3 tools/exp/train_rec.py --selfcheck

echo "== sanity: full offline verification chain (export + exactness + smoke) =="
PYTHONPATH="$DEPS:$REPO/indra:$REPO/tools" bash tools/exp/verify_bundle.sh || {
  echo "verify_bundle.sh FAILED — STOP and report before touching any data"; exit 1; }

echo "DONE. Paste results/probe.json + results/verify/*.json back into the session."