Upload code/train.py with huggingface_hub
Browse files562 unmodified lines563564565566567568562 unmodified linesdist.barrier()if IS_MAIN and val_loss is not None:log(f"step {step} | val_loss {val_loss:.4f}")if best_val_loss is None or val_loss < best_val_loss:best_val_loss = val_loss# User requested not to save/upload ckpt_best.pt to save time562 unmodified lines563564565566567568569570571572573574575576577578579580581582583584585586587588589590562 unmodified linesdist.barrier()if IS_MAIN and val_loss is not None:log(f"step {step} | val_loss {val_loss:.4f}")# Live Pretrain Text Generation Test (Rank 0)try:from tokenizers import Tokenizertok_paths = [f"{WORK}/tokenizer/tokenizer.json", "tokenizer/tokenizer.json"]tok_f = next((p for p in tok_paths if os.path.exists(p)), None)if tok_f:_tok = Tokenizer.from_file(tok_f)test_prompts = ["In science, photosynthesis is","In 1930, Mahatma Gandhi led the","The capital city of India is"]p_sel = test_prompts[(step // EVAL_EVERY) % len(test_prompts)]raw_m = unwrap_model(model)raw_m.eval()t_in = torch.tensor([_tok.encode(p_sel).ids], dtype=torch.long, device=DEVICE)t_out = raw_m.generate(t_in, max_new_tokens=30, temperature=0.3, top_p=0.9)gen_txt = _tok.decode(t_out[0].tolist())log(f" 💬 [Live Pretrain Test @ Step {step}]: \"{gen_txt}\"")raw_m.train()except Exception:passif best_val_loss is None or val_loss < best_val_loss:best_val_loss = val_loss# User requested not to save/upload ckpt_best.pt to save time
code/train.py+22