zziang commited on
Commit
b4f7efa
·
verified ·
1 Parent(s): 533d158

Upload kaggle/notebook_director_lora.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. kaggle/notebook_director_lora.py +15 -4
kaggle/notebook_director_lora.py CHANGED
@@ -31,12 +31,20 @@ FILES = {"director_lora/sft.jsonl": SFT, "kaggle/director_lora_train.py": TRAIN}
31
  PIP = ("pip install -q --upgrade "
32
  "'transformers==5.22.2' 'huggingface_hub>=1.31,<2' "
33
  "'peft==0.21.2' 'accelerate>=1.1'")
 
 
 
 
 
34
  CHECK = (sys.executable + " -c \""
35
- "import torch, transformers, peft, huggingface_hub; "
36
  "print('torch', torch.__version__, 'cuda', torch.version.cuda, "
37
  "'gpus', torch.cuda.device_count()); "
38
  "print('transformers', transformers.__version__, "
39
- "'peft', peft.__version__, 'hub', huggingface_hub.__version__)\"")
 
 
 
40
 
41
 
42
  def log(msg: str) -> None:
@@ -74,8 +82,10 @@ def main() -> None:
74
 
75
  if run(PIP) != 0:
76
  raise SystemExit("dependency install failed")
 
 
77
  if run(CHECK) != 0:
78
- raise SystemExit("environment check failed (torch/hub mismatch?)")
79
 
80
  env = dict(os.environ, WORK_ROOT=str(ROOT), DATA=str(SFT), LORA_OUT=str(OUT),
81
  CUDA_VISIBLE_DEVICES="0", HF_HUB_DISABLE_XET="1",
@@ -86,7 +96,8 @@ def main() -> None:
86
  MAX_LEN=os.environ.get("MAX_LEN", "2048"),
87
  ACCUM=os.environ.get("ACCUM", "4"),
88
  DTYPE=os.environ.get("DTYPE", "auto"),
89
- GRAD_CKPT=os.environ.get("GRAD_CKPT", "0"))
 
90
  log(f"training on {SFT}")
91
  rc = subprocess.run([sys.executable, str(TRAIN)], env=env).returncode
92
  log(f"train rc={rc}; outputs in {OUT}")
 
31
  PIP = ("pip install -q --upgrade "
32
  "'transformers==5.22.2' 'huggingface_hub>=1.31,<2' "
33
  "'peft==0.21.2' 'accelerate>=1.1'")
34
+ # The Kaggle image ships torchao 0.10.0. peft 0.21.2 raises ImportError when
35
+ # it finds torchao < 0.16 instead of ignoring it, even for plain fp16 LoRA.
36
+ # We never quantize here, so remove it; the training script also patches the
37
+ # peft probe as a fallback.
38
+ UNINSTALL = "pip uninstall -y -q torchao"
39
  CHECK = (sys.executable + " -c \""
40
+ "import importlib.util, torch, transformers, peft, huggingface_hub; "
41
  "print('torch', torch.__version__, 'cuda', torch.version.cuda, "
42
  "'gpus', torch.cuda.device_count()); "
43
  "print('transformers', transformers.__version__, "
44
+ "'peft', peft.__version__, 'hub', huggingface_hub.__version__); "
45
+ "print('torchao spec', importlib.util.find_spec('torchao')); "
46
+ "assert importlib.util.find_spec('torchao') is None, "
47
+ "'torchao still installed'\"")
48
 
49
 
50
  def log(msg: str) -> None:
 
82
 
83
  if run(PIP) != 0:
84
  raise SystemExit("dependency install failed")
85
+ if run(UNINSTALL) != 0:
86
+ log("WARN: torchao uninstall returned non-zero; peft fallback will handle it")
87
  if run(CHECK) != 0:
88
+ raise SystemExit("environment check failed (torch/hub/torchao mismatch?)")
89
 
90
  env = dict(os.environ, WORK_ROOT=str(ROOT), DATA=str(SFT), LORA_OUT=str(OUT),
91
  CUDA_VISIBLE_DEVICES="0", HF_HUB_DISABLE_XET="1",
 
96
  MAX_LEN=os.environ.get("MAX_LEN", "2048"),
97
  ACCUM=os.environ.get("ACCUM", "4"),
98
  DTYPE=os.environ.get("DTYPE", "auto"),
99
+ GRAD_CKPT=os.environ.get("GRAD_CKPT", "0"),
100
+ MAX_TRAIN_SECONDS=os.environ.get("MAX_TRAIN_SECONDS", "4200"))
101
  log(f"training on {SFT}")
102
  rc = subprocess.run([sys.executable, str(TRAIN)], env=env).returncode
103
  log(f"train rc={rc}; outputs in {OUT}")