Restore flash-attn + add progress logs to cells 3/4/5
Browse files- colab/OmniSub_Colab.ipynb +42 -18
colab/OmniSub_Colab.ipynb
CHANGED
|
@@ -42,28 +42,39 @@
|
|
| 42 |
"cell_type": "code",
|
| 43 |
"metadata": {},
|
| 44 |
"source": [
|
| 45 |
-
"# 3) Lấy MÃ NGUỒN từ Hugging Face Hub + cài phụ thuộc\n",
|
| 46 |
-
"HF_REPO = 'STBack23/OmniSub'
|
| 47 |
-
"HF_REPO_TYPE = 'model'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
"\n",
|
| 49 |
-
"import os\n",
|
| 50 |
"%cd /content\n",
|
|
|
|
| 51 |
"!pip install -q -U huggingface_hub\n",
|
| 52 |
"from huggingface_hub import snapshot_download\n",
|
| 53 |
-
"
|
| 54 |
"snapshot_download(repo_id=HF_REPO, repo_type=HF_REPO_TYPE, local_dir='/content/Gemma')\n",
|
| 55 |
"%cd /content/Gemma\n",
|
| 56 |
"\n",
|
|
|
|
| 57 |
"!pip install -q -e .[colab]\n",
|
| 58 |
-
"
|
| 59 |
"!pip install -q -U \"git+https://github.com/huggingface/transformers\"\n",
|
| 60 |
"!pip install -q -U qwen-omni-utils\n",
|
| 61 |
-
"
|
| 62 |
-
"
|
| 63 |
-
"
|
| 64 |
-
"# !pip install -q -U flash-attn --no-build-isolation\n",
|
| 65 |
"!apt-get -qq install -y ffmpeg\n",
|
| 66 |
-
"
|
| 67 |
],
|
| 68 |
"execution_count": null,
|
| 69 |
"outputs": []
|
|
@@ -91,16 +102,20 @@
|
|
| 91 |
" return None\n",
|
| 92 |
"\n",
|
| 93 |
"stem = os.path.splitext(MOVIE)[0]\n",
|
|
|
|
|
|
|
|
|
|
| 94 |
"SRT = _find(stem, ['.srt'])\n",
|
| 95 |
"VIDEO = _find(stem, _VIDEO_EXTS)\n",
|
| 96 |
"\n",
|
| 97 |
-
"assert SRT, f\"Không thấy '{stem}.srt' trong {PHIM_DIR}.
|
| 98 |
"if not VIDEO:\n",
|
| 99 |
-
" print(f\"⚠️ Không thấy video cho '{stem}' — chạy được Bước 1, nhưng Bước 4 cần video.\")\n",
|
| 100 |
"\n",
|
| 101 |
-
"print('Phim :', stem)\n",
|
| 102 |
-
"print('SRT :', SRT)\n",
|
| 103 |
-
"print('Video:', VIDEO)"
|
|
|
|
| 104 |
],
|
| 105 |
"execution_count": null,
|
| 106 |
"outputs": []
|
|
@@ -109,18 +124,27 @@
|
|
| 109 |
"cell_type": "code",
|
| 110 |
"metadata": {},
|
| 111 |
"source": [
|
| 112 |
-
"# 5) Nạp model Qwen3-Omni 4-bit (
|
|
|
|
| 113 |
"from omnisub.config import Config\n",
|
| 114 |
"from omnisub.backends.transformers_qwen import TransformersQwenOmniBackend\n",
|
| 115 |
"\n",
|
| 116 |
"config = Config.load('config.yaml')\n",
|
|
|
|
|
|
|
|
|
|
| 117 |
"backend = TransformersQwenOmniBackend(\n",
|
| 118 |
" model_name=config.models['omni'],\n",
|
| 119 |
" quant=config.models['quant'],\n",
|
| 120 |
" cache_dir=CACHE,\n",
|
| 121 |
")\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
"backend.load()\n",
|
| 123 |
-
"print('Model đã nạp xong.')"
|
| 124 |
],
|
| 125 |
"execution_count": null,
|
| 126 |
"outputs": []
|
|
|
|
| 42 |
"cell_type": "code",
|
| 43 |
"metadata": {},
|
| 44 |
"source": [
|
| 45 |
+
"# 3) Lấy MÃ NGUỒN từ Hugging Face Hub + cài phụ thuộc (có log tiến trình)\n",
|
| 46 |
+
"HF_REPO = 'STBack23/OmniSub' # ← repo HF chứa mã nguồn dự án\n",
|
| 47 |
+
"HF_REPO_TYPE = 'model' # 'model' | 'dataset' | 'space'\n",
|
| 48 |
+
"\n",
|
| 49 |
+
"import os, time\n",
|
| 50 |
+
"from getpass import getpass\n",
|
| 51 |
+
"\n",
|
| 52 |
+
"# HF token cho pyannote (Bước 2). Nhập 1 lần ở đây; các cell sau dùng lại.\n",
|
| 53 |
+
"if not os.environ.get('HF_TOKEN'):\n",
|
| 54 |
+
" os.environ['HF_TOKEN'] = getpass('HF token (pyannote): ')\n",
|
| 55 |
+
"\n",
|
| 56 |
+
"_t0 = time.time()\n",
|
| 57 |
+
"def _log(msg):\n",
|
| 58 |
+
" print(f\"\\n===== {msg} (+{time.time()-_t0:.0f}s) =====\", flush=True)\n",
|
| 59 |
"\n",
|
|
|
|
| 60 |
"%cd /content\n",
|
| 61 |
+
"_log('[1/6] Cài huggingface_hub')\n",
|
| 62 |
"!pip install -q -U huggingface_hub\n",
|
| 63 |
"from huggingface_hub import snapshot_download\n",
|
| 64 |
+
"_log(f'[2/6] Tải mã nguồn từ HF: {HF_REPO}')\n",
|
| 65 |
"snapshot_download(repo_id=HF_REPO, repo_type=HF_REPO_TYPE, local_dir='/content/Gemma')\n",
|
| 66 |
"%cd /content/Gemma\n",
|
| 67 |
"\n",
|
| 68 |
+
"_log('[3/6] Cài OmniSub + phụ thuộc Colab (torch, pyannote, librosa...) — vài phút')\n",
|
| 69 |
"!pip install -q -e .[colab]\n",
|
| 70 |
+
"_log('[4/6] Cài transformers bản nguồn cho Qwen3-Omni — vài phút')\n",
|
| 71 |
"!pip install -q -U \"git+https://github.com/huggingface/transformers\"\n",
|
| 72 |
"!pip install -q -U qwen-omni-utils\n",
|
| 73 |
+
"_log('[5/6] Biên dịch flash-attn — RẤT LÂU (10-30 phút). Có log build bên dưới nghĩa là vẫn chạy.')\n",
|
| 74 |
+
"!pip install -U flash-attn --no-build-isolation\n",
|
| 75 |
+
"_log('[6/6] Cài ffmpeg')\n",
|
|
|
|
| 76 |
"!apt-get -qq install -y ffmpeg\n",
|
| 77 |
+
"_log('✅ XONG — mã nguồn & phụ thuộc đã sẵn sàng')"
|
| 78 |
],
|
| 79 |
"execution_count": null,
|
| 80 |
"outputs": []
|
|
|
|
| 102 |
" return None\n",
|
| 103 |
"\n",
|
| 104 |
"stem = os.path.splitext(MOVIE)[0]\n",
|
| 105 |
+
"print('🔍 Dò trong thư mục:', PHIM_DIR)\n",
|
| 106 |
+
"print(' File hiện có :', os.listdir(PHIM_DIR))\n",
|
| 107 |
+
"\n",
|
| 108 |
"SRT = _find(stem, ['.srt'])\n",
|
| 109 |
"VIDEO = _find(stem, _VIDEO_EXTS)\n",
|
| 110 |
"\n",
|
| 111 |
+
"assert SRT, f\"❌ Không thấy '{stem}.srt' trong {PHIM_DIR}.\"\n",
|
| 112 |
"if not VIDEO:\n",
|
| 113 |
+
" print(f\"⚠️ Không thấy video cho '{stem}' — chạy được Bước 1, nhưng Bước 2-4 cần video.\")\n",
|
| 114 |
"\n",
|
| 115 |
+
"print('✅ Phim :', stem)\n",
|
| 116 |
+
"print('✅ SRT :', SRT)\n",
|
| 117 |
+
"print('✅ Video:', VIDEO)\n",
|
| 118 |
+
"print('✅ Token:', 'có' if os.environ.get('HF_TOKEN') else 'CHƯA có (Bước 2 sẽ lỗi)')"
|
| 119 |
],
|
| 120 |
"execution_count": null,
|
| 121 |
"outputs": []
|
|
|
|
| 124 |
"cell_type": "code",
|
| 125 |
"metadata": {},
|
| 126 |
"source": [
|
| 127 |
+
"# 5) Nạp model Qwen3-Omni 4-bit (lần đầu tải ~30-60GB về Drive, RẤT LÂU)\n",
|
| 128 |
+
"import time\n",
|
| 129 |
"from omnisub.config import Config\n",
|
| 130 |
"from omnisub.backends.transformers_qwen import TransformersQwenOmniBackend\n",
|
| 131 |
"\n",
|
| 132 |
"config = Config.load('config.yaml')\n",
|
| 133 |
+
"print('⏳ Model:', config.models['omni'], '| quant:', config.models['quant'])\n",
|
| 134 |
+
"print('⏳ Cache :', CACHE, '(lần sau đọc lại từ đây, đỡ phải tải)')\n",
|
| 135 |
+
"\n",
|
| 136 |
"backend = TransformersQwenOmniBackend(\n",
|
| 137 |
" model_name=config.models['omni'],\n",
|
| 138 |
" quant=config.models['quant'],\n",
|
| 139 |
" cache_dir=CACHE,\n",
|
| 140 |
")\n",
|
| 141 |
+
"\n",
|
| 142 |
+
"print('⏳ Đang tải/nạp model... Theo dõi 2 thanh tiến trình bên dưới:')\n",
|
| 143 |
+
"print(' • \"Downloading ...\" = đang tải trọng số (chỉ lần đầu)')\n",
|
| 144 |
+
"print(' • \"Loading checkpoint shards: x/y\" = đang nạp vào VRAM')\n",
|
| 145 |
+
"_t = time.time()\n",
|
| 146 |
"backend.load()\n",
|
| 147 |
+
"print(f'✅ Model đã nạp xong sau {time.time()-_t:.0f}s. Attention dùng: {backend.attn_implementation}')"
|
| 148 |
],
|
| 149 |
"execution_count": null,
|
| 150 |
"outputs": []
|