{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"tpuV5e8","dataSources":[{"sourceType":"competition","sourceId":6799,"databundleVersionId":4225553},{"sourceType":"datasetVersion","sourceId":15302770,"datasetId":9788327,"databundleVersionId":16207074},{"sourceType":"datasetVersion","sourceId":15079638,"datasetId":9654486,"databundleVersionId":15962693},{"sourceType":"datasetVersion","sourceId":15080290,"datasetId":9654925,"databundleVersionId":15963418},{"sourceType":"datasetVersion","sourceId":15305584,"datasetId":9789263,"databundleVersionId":16210141},{"sourceType":"datasetVersion","sourceId":15306886,"datasetId":9790842,"databundleVersionId":16211592},{"sourceType":"modelInstanceVersion","sourceId":790106,"databundleVersionId":16139164,"modelInstanceId":602982,"modelId":615107},{"sourceType":"modelInstanceVersion","sourceId":778993,"databundleVersionId":15986359,"modelInstanceId":594436,"modelId":606702}],"dockerImageVersionId":31288,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"%pip uninstall -y jax jaxlib libtpu optax flax chex orbax-checkpoint\n%pip install --no-cache-dir -U \"jax[tpu]\" -f https://storage.googleapis.com/jax-releases/libtpu_releases.html\n%pip install --no-cache-dir -U flax optax chex orbax-checkpoint grain-balsa wandb diffusers transformers einops torchmetrics","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-26T08:44:27.890279Z","iopub.execute_input":"2026-04-26T08:44:27.890516Z","iopub.status.idle":"2026-04-26T08:44:59.352064Z","shell.execute_reply.started":"2026-04-26T08:44:27.890496Z","shell.execute_reply":"2026-04-26T08:44:59.350938Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!rm -rf /kaggle/working/Self-Flow","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-26T08:44:59.352935Z","iopub.execute_input":"2026-04-26T08:44:59.353128Z","iopub.status.idle":"2026-04-26T08:44:59.549254Z","shell.execute_reply.started":"2026-04-26T08:44:59.353106Z","shell.execute_reply":"2026-04-26T08:44:59.548314Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!git clone -b feat/depth-shortcut-predictor https://github.com/thanhlamauto/Self-Flow.git","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-04-26T08:44:59.550026Z","iopub.execute_input":"2026-04-26T08:44:59.550221Z","iopub.status.idle":"2026-04-26T08:45:00.835688Z","shell.execute_reply.started":"2026-04-26T08:44:59.550202Z","shell.execute_reply":"2026-04-26T08:45:00.834483Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%cd /kaggle/working/Self-Flow","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-26T08:45:00.836626Z","iopub.execute_input":"2026-04-26T08:45:00.836813Z","iopub.status.idle":"2026-04-26T08:45:00.841541Z","shell.execute_reply.started":"2026-04-26T08:45:00.83679Z","shell.execute_reply":"2026-04-26T08:45:00.840899Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!pip install --upgrade --force-reinstall protobuf==7.34.1 wandb\n!pip install -q array-record","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-26T08:45:00.842333Z","iopub.execute_input":"2026-04-26T08:45:00.842498Z","iopub.status.idle":"2026-04-26T08:45:20.877195Z","shell.execute_reply.started":"2026-04-26T08:45:00.842482Z","shell.execute_reply":"2026-04-26T08:45:20.876227Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nimport wandb\n\nfrom kaggle_secrets import UserSecretsClient\nuser_secrets = UserSecretsClient()\nsecret_value_0 = user_secrets.get_secret(\"HF_TOKEN\")\nsecret_value_1 = user_secrets.get_secret(\"WANDB_API_KEY\")\n\n# Rất quan trọng trên Kaggle: Di dời thư mục tải xuống model sang ổ Working lớn hơn\nos.environ[\"HF_HOME\"] = \"/kaggle/working/huggingface_cache\" \nos.environ[\"TORCH_HOME\"] = \"/kaggle/working/torch_cache\"\nos.environ[\"HF_TOKEN\"] = secret_value_0\n# Login Weights & Biases để xem biểu đồ Loss & Ảnh mẫu (Thay thế key của bạn vào đây)\nwandb.login(key=\"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\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-26T08:45:20.878027Z","iopub.execute_input":"2026-04-26T08:45:20.878232Z","iopub.status.idle":"2026-04-26T08:45:24.814939Z","shell.execute_reply.started":"2026-04-26T08:45:20.87821Z","shell.execute_reply":"2026-04-26T08:45:24.813915Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!git pull","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-26T08:45:24.815605Z","iopub.execute_input":"2026-04-26T08:45:24.815855Z","iopub.status.idle":"2026-04-26T08:45:25.135352Z","shell.execute_reply.started":"2026-04-26T08:45:24.815838Z","shell.execute_reply":"2026-04-26T08:45:25.134202Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%pip install --no-cache-dir -U \"jax[tpu]\" -f https://storage.googleapis.com/jax-releases/libtpu_releases.html\n%pip install --no-cache-dir -U flax optax chex orbax-checkpoint grain wandb diffusers transformers einops torchmetrics","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-26T08:45:25.136293Z","iopub.execute_input":"2026-04-26T08:45:25.136479Z","iopub.status.idle":"2026-04-26T08:45:47.6397Z","shell.execute_reply.started":"2026-04-26T08:45:25.136459Z","shell.execute_reply":"2026-04-26T08:45:47.638418Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!python train.py --model-size B --batch-size 128 --epochs 400 --steps-per-epoch 1000 --learning-rate 1e-4 --vae-model /kaggle/input/models/damtrunghieu/sdvae-ema/flax/default/1 --data-path /kaggle/input/datasets/thaygiaodaysat/imagenet-vae-latents-ar-v2 --val-data-path /kaggle/input/datasets/thaygiaodaysat/imagenet-vae-latents-train-v3 --grad-clip 1.0 --log-freq 100 --eval-freq 1000 --eval-batches 4 --sample-freq 5000 --sample-num-steps 50 --sample-cfg-scale 1.0 --fid-freq 25000 --num-fid-samples 4096 --fid-batch-size 256 --fid-eval-local-batch 32 --fid-num-steps 50 --fid-cfg-scale 1.0 --vae-decode-batch-size 256 --no-linear-probe --inception-score-weights /kaggle/input/models/ctlcmleon/inception-v3/pytorch/default/1/inception_v3_google-0cc3c7bd.pth --block-corr-freq 25000 --block-corr-batches 2 --preflight-checks --preflight-fid-memory-probe --wandb-project selfflow-jax --ema-decay 0.9999 --shortcut-predictor dilated_small --shortcut-training-mode direction-magnitude-skip --shortcut-lambda-dir 0.5 --shortcut-lambda-boot 0.25 --shortcut-lambda-mag 0.375 --shortcut-lambda-boot-mag 0.1875 --shortcut-mag-scale 3.0 --shortcut-mag-abs-center 5.5 --shortcut-mag-abs-scale 1.5 --shortcut-mag-clip-min 3.0 --shortcut-mag-clip-max 8.0 --shortcut-skip-in-loop-gap-mode truncated-normal --shortcut-skip-in-loop-max-gap 10 --shortcut-skip-in-loop-gap-loc 3.0 --shortcut-skip-in-loop-gap-sigma 2.0 --shortcut-skip-in-loop-warmup-steps 5000 --shortcut-skip-in-loop-detach-source --ckpt-dir ./checkpoints/checkpoints-depth-shortcut-dilated-small-skiploop-p005_l010_tn10 --shortcut-skip-in-loop-prob 0.05 --shortcut-lambda-skip-fm 0.10 --shortcut-bootstrap-detach-source --private-loss --lambda-private 1.0 --private-max-pairs 2","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-26T08:45:47.640259Z","iopub.execute_input":"2026-04-26T08:45:47.640456Z","execution_failed":"2026-04-26T17:40:13.087Z"}},"outputs":[],"execution_count":null}]}