Run this model with HF Jobs
Run dllwa/gemma4-form-report-lora on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/dllwa/gemma4-form-report-lora. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/dllwa/gemma4-form-report-lora on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use dllwa/gemma4-form-report-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use dllwa/gemma4-form-report-lora with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("google/gemma-4-31B-it") model = PeftModel.from_pretrained(base_model, "dllwa/gemma4-form-report-lora") - Notebooks
- Google Colab
- Kaggle
Download code/src/common/gpu_guard.py from dllwa/gemma4-form-report-lora: direct link, hf CLI and curl.
- Browser
- Download file 6.19 kB
-
https://huggingface.co/dllwa/gemma4-form-report-lora/resolve/main/code/src/common/gpu_guard.py
- Command line
-
hf download hf://dllwa/gemma4-form-report-lora/code/src/common/gpu_guard.py
-
curl -L -o gpu_guard.py https://huggingface.co/dllwa/gemma4-form-report-lora/resolve/main/code/src/common/gpu_guard.py
6.19 kB
| #!/usr/bin/env python3 | |
| """๊ณต์ฉ GPU ์๋ฒ ๋ณดํธ ๊ฐ๋ โ **GPU ๋ฅผ ์ฐ๋ ์ฐ๋ฆฌ ์์ ์ ๋ถ๊ฐ ์ด๊ฑธ ํต๊ณผํด์ผ ํ๋ค.** | |
| `D-022`: *"GPU ๋ฅผ ์ฐ๋ ์ฐ๋ฆฌ ์์ ์ **์์ธ ์์ด** `/tmp/lora_tune.lock` ์ ์ฅ ์ฑ ์คํํ๋ค."* | |
| **์ ๋ณ๋ ๋ชจ๋์ธ๊ฐ** *(2026-08-14 ๋ถ๋ฆฌ)*. ์๋ ์ด ๊ฐ๋๋ `train_lora.py` ์์๋ง ์์๋ค. | |
| ๊ทธ๋์ **ํ๊ฐ(`src/eval/generate.py`)๋ ์๋ฌด๊ฒ๋ ๋ง์ง ์์๋ค** โ ๋ฝ ์์ด ๋์ ์ํ์ผ๋ก | |
| ์์ฑ์ ๋๋ ค๋ ์ฝ๋๊ฐ ํต๊ณผ์์ผฐ๋ค. ๊ท์น์ `D-022` ์ ์์์ง๋ง **ํ์ต์๋ง ์ฝ๋๊ฐ ๋ถ์ด ์์๋ค.** | |
| `N-032`/`D-022` ๊ฐ flock ์ ๋ํด ๋ด๋ฆฐ ๊ฒฐ๋ก ์ด ์ฌ๊ธฐ์๋ ์ ์ฉ๋๋ค: | |
| > **๊ท์น์ ์ฌ๋ ๊ธฐ์ต์ ๋งก๊ธฐ๋ฉด ์ธ์ ๊ฐ ์๋๋ค. ๊ทธ๋์ ์ฝ๋๊ฐ ๋ง๋๋ค.** | |
| ๋ณต์ ํ์ง ์๊ณ **ํ ๊ณณ์ ๋๋** ์ด์ ๋ ๊ฐ๋ค โ ๊ฐ์ ์์๋ฅผ ๋ ํ์ผ์ ๋๋ฉด ๊ฐ๋ผ์ง๋ค. | |
| (2026-08-14 ํ๋ฃจ ๋์ ๋ฌธ์์์ ๊ทธ ํจํด์ ๋ฐ๋ณตํด์ ๋ดค๋ค.) | |
| ์ฐ๋ ๊ณณ: `src/train/train_lora.py`, `src/eval/generate.py` | |
| """ | |
| import math | |
| import os | |
| import torch | |
| #: burst ์ ๊ณต์กดํ ์ ์๋ ์ฅ๋น ์ต๋์น(GiB). ์ด๊ฑธ ๋๊ฒจ ์ฐ๋ ค๋ฉด ๋ฝ์ ์ฅ์ด์ผ ํ๋ค. | |
| #: ๊ทผ๊ฑฐ (2026-08-12 ์ ์ โ ์ดํ์ 31.8 ์ด์๋ค): | |
| #: โ ๏ธ ๋นผ๊ธฐ์ ์ถ๋ฐ์ ์ `nvidia-smi` ์ **total(143,771)** ์ด ์๋๋ผ | |
| #: **used+free(143,157)** ๋ค. ๊ทธ 614 MiB ์ฐจ์ด๋ ์ฐ๋ฆฌ๊ฐ ํ ๋นํ ์ ์๋ ๋ชซ์ด๋ผ | |
| #: total ์์ ๋นผ๋ฉด ์๋ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์์ฐ์ ๋ฃ๊ฒ ๋๋ค. | |
| #: ๊ทผ๊ฑฐ๋ `06` C-3 ์ **burst ์ค ์ต์ free ์ง์ ์ค์ธก 31,960 MiB** ํ๋๋ค. | |
| #: 143,157 โ 72,313(vLLM) โ 38,884(burst) ๋ก๋ ๊ฐ์ ๊ฐ์ด ๋์ค์ง๋ง **๋ ๋ฆฝ ํ์ธ์ด ์๋๋ค** | |
| #: โ 38,884 ์์ฒด๊ฐ 111,197โ72,313 ์ด๋ผ ์ฐ์์ ํผ์น๋ฉด ํญ์ min free ์ ๊ฐ์์ง๋ค. | |
| #: (D-022 / N-032. ์ดํ 31.8 ์ ์๋ 0.6 GiB ๋ฅผ ์ธ ์ ์๋ค๊ณ ๋ฏฟ๋ ๊ฐ์ด์๋ค) | |
| BURST_SAFE_GIB = 31.21 | |
| BURST_LOCK = "/tmp/lora_tune.lock" | |
| def _ancestor_holds_burst_lock() -> bool: | |
| """**์ฐ๋ฆฌ ์กฐ์ ํ๋ก์ธ์ค**๊ฐ burst ๋ฝ ํ์ผ์ ์ด๊ณ ์๋๊ฐ. | |
| โ ๏ธ "๋๊ตฐ๊ฐ ๋ฝ์ ์ฅ๊ณ ์๋๊ฐ"๋ก๋ ์ ๋๋ค. ์ดํ์ด ๊ทธ๋ ๊ฒ ํ๋ค๊ฐ | |
| **burst ๊ฐ ์ฅ๊ณ ์๋ ์ํฉ์ '๋ถ๋ชจ๊ฐ ์ฅ๊ณ ์๋ค'๋ก ์ค์ธํด ํต๊ณผ**์์ผฐ๋ค. | |
| ๊ทธ๊ฑด ์ ํํ ๋ง์์ผ ํ ๊ฒฝ์ฐ๋ค(burst 38.0GiB + ์ฐ๋ฆฌ 64.3GiB โ ์นด๋ ์ด๊ณผ). | |
| `flock <ํ์ผ> <๋ช ๋ น>` ์ ๊ทธ ํ์ผ์ ์ฐ ์ฑ๋ก ๋ช ๋ น์ exec ํ๋ฏ๋ก, ๋ฝ์ ์ฅ | |
| ํ๋ก์ธ์ค๋ **์ฐ๋ฆฌ ์กฐ์**์ด๋ค. ์กฐ์๋ค์ `/proc/<pid>/fd` ์ ๊ทธ ํ์ผ๋ก ๊ฐ๋ | |
| ์ฌ๋ณผ๋ฆญ ๋งํฌ๊ฐ ์๋์ง ๋ณธ๋ค. torchrun ์ฒ๋ผ ์ค๊ฐ ํ๋ก์ธ์ค๊ฐ ๊ปด๋ ์กฐ์ ์ฌ์ฌ์ | |
| ํ๊ณ ์ฌ๋ผ๊ฐ๋ฏ๋ก ์ฐพ์ ์ ์๋ค. | |
| ํ์ธ์ ์คํจํ๋ฉด **์ ์ฅ ๊ฒ์ผ๋ก ๋ณธ๋ค**(์์ ํ ์ชฝ). ์๋ชป ํต๊ณผ์ํค๋ ๊ฒ๋ณด๋ค | |
| ์๋ชป ๋ง๋ ํธ์ด ๋ซ๋ค โ ๋งํ๋ฉด ์ฆ์ ์์ง๋ง, ํต๊ณผํ๋ฉด ๋ช ์๊ฐ ๋ค์ ์ฃฝ๋๋ค. | |
| """ | |
| try: | |
| pid = os.getppid() | |
| for _ in range(20): # ๋ฌดํ ๋ฃจํ ๋ฐฉ์ง | |
| if pid <= 1: | |
| break | |
| fddir = f"/proc/{pid}/fd" | |
| try: | |
| for e in os.listdir(fddir): | |
| try: | |
| if os.readlink(os.path.join(fddir, e)) == BURST_LOCK: | |
| return True | |
| except OSError: | |
| pass # ์ฌ๋ผ์ง fd โ ๋ฌด์ | |
| except OSError: | |
| pass # ๊ถํ ์๊ฑฐ๋ ์ฃฝ์ ํ๋ก์ธ์ค | |
| # ๋ถ๋ชจ์ ๋ถ๋ชจ๋ก. `/proc/<pid>/stat` ๋ `pid (comm) state ppid ...` | |
| # ์ธ๋ฐ comm ์ ๊ณต๋ฐฑยท๊ดํธ๊ฐ ๋ค์ด๊ฐ ์ ์์ด ๋ง์ง๋ง ") " ๋ก ์๋ฅธ๋ค. | |
| with open(f"/proc/{pid}/stat", encoding="utf-8") as f: | |
| pid = int(f.read().rsplit(") ", 1)[1].split()[1]) | |
| except Exception: | |
| return False | |
| return False | |
| def require_burst_lock_if_needed(fraction: float): | |
| """โ ์ํ์ด burst ๊ณต์กด์ ์ ๋๋๋ฐ ๋ฝ์ด ์์ผ๋ฉด **์์์ ๊ฑฐ๋ถํ๋ค.** (N-032) | |
| D-022 ๋ก "์ฐ๋ฆฌ ์์ ์ ํญ์ flock ์ ์ฅ ์ฑ ์คํํ๋ค"๊ฐ ํ์ ๋๋ค. ๊ทธ๋ฐ๋ฐ ๊ท์น์ | |
| ์ฌ๋ ๊ธฐ์ต์ ๋งก๊ธฐ๋ฉด ์ธ์ ๊ฐ ์๋๋ค. ์๊ณ ๋์ ์ํ์ผ๋ก ์คํํ๋ฉด burst ๊ฐ 74.5๋ถ๋ง๋ค | |
| ๊นจ์ด๋ 32B ๋ชจ๋ธ ์ ์ฌ๋ฅผ ์๋ํ๋ฉฐ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ ์ํ๊ณ , **์ฃฝ๋ ๊ฒ์ burst ๊ฐ ์๋๋ผ | |
| ๋ช ์๊ฐ์งธ ๋๋ ์ฐ๋ฆฌ ํ์ต**์ด ๋ ์ ์๋ค. | |
| ๊ทธ๋์ ์ฝ๋๊ฐ ๋ง๋๋ค. ๋ฝ์ **๋ถ๋ชจ ํ๋ก์ธ์ค**(`flock ... <๋ช ๋ น>`)๊ฐ ์ฅ๊ณ ์์ผ๋ฏ๋ก, | |
| ์ฌ๊ธฐ์ ์ฐ๋ฆฌ๊ฐ ๋ฝ์ ์ก์ผ๋ ค ํ๋ฉด ์ ๋๋ค โ ์ก์ผ๋ฉด ๋ถ๋ชจ๊ฐ ๋์ ๋ ๊ฐ์ด ํ๋ฆฐ๋ค. | |
| ํ์ธํด์ผ ํ ๊ฒ์ "๋๊ตฐ๊ฐ ์ฅ๊ณ ์๋๊ฐ"๊ฐ ์๋๋ผ **"์ฐ๋ฆฌ ์กฐ์์ด ์ฅ๊ณ ์๋๊ฐ"**๋ค. | |
| (๊ทธ ๋์ ํผ๋ํ ์ดํ์ด ์ค์ ๋ก burst ๊ฐ๋ ์ค์ ํต๊ณผ์์ผฐ๋ค โ `_ancestor_holds_burst_lock` ์ฐธ๊ณ ) | |
| ์ฌ๋ฐ๋ฅธ ์คํ: | |
| nohup flock /tmp/lora_tune.lock <ํ์ต ๋ช ๋ น> & | |
| """ | |
| if not torch.cuda.is_available(): | |
| return | |
| total_gib = torch.cuda.get_device_properties(0).total_memory / 1024**3 | |
| ours_gib = total_gib * fraction | |
| if ours_gib <= BURST_SAFE_GIB: | |
| return # burst ์ ๊ณต์กด ๊ฐ๋ฅํ ๋ฒ์ โ ๋ฝ์ด ์์ด๋ ๋จ์ ์ฃฝ์ด์ง ์๋๋ค | |
| if _ancestor_holds_burst_lock(): | |
| return # ์ฐ๋ฆฌ ๋ถ๋ชจ(flock)๊ฐ ์ฅ๊ณ ์๋ค โ ์ ์ | |
| raise SystemExit( | |
| f"\n[์ค๋จ] ์ํ {ours_gib:.1f}GiB ๋ burst ๊ณต์กด์ ({BURST_SAFE_GIB}GiB)์ ๋๋๋ฐ " | |
| f"`{BURST_LOCK}` ์ ์ฅ๊ณ ์์ง ์๋ค.\n" | |
| f" ์ด๋๋ก ๋๋ฉด burst ๊ฐ 74.5๋ถ๋ง๋ค ์ ์ฌ๋ฅผ ์๋ํ๋ฉฐ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ ์ํด " | |
| f"**์ด ํ์ต์ด ์ฃฝ์ ์ ์๋ค.**\n\n" | |
| f" ์ด๋ ๊ฒ ์คํํ๋ผ (D-022):\n" | |
| f" nohup flock {BURST_LOCK} <ํ์ต ๋ช ๋ น> &\n\n" | |
| f" burst ์ ๊ณต์กด์ํค๋ ค๋ฉด --mem_fraction ์ " | |
| # ๋ด๋ฆผํ๋ค โ ๋ฐ์ฌ๋ฆผํ๋ฉด ๊ณต์กด์ ์ ์์ฃผ ์ด์ง ๋๋ ๊ฐ์ ์๋ดํ๊ฒ ๋๋ค | |
| f"{math.floor(BURST_SAFE_GIB / total_gib * 1000) / 1000} ์ดํ๋ก ๋ฎ์ถฐ๋ผ.\n") | |