Repository navigation
Add nanogpt example - #308
Conversation
Signed-off-by: Hao Wu <skyw@nvidia.com>
Signed-off-by: Hao Wu <skyw@nvidia.com>
|
| "lr_decay_iters", | ||
| "min_lr", | ||
| ): | ||
| config[key] = checkpoint["config"][key] |
There was a problem hiding this comment.
Restart forgets saved context length
Resuming a checkpoint with a nondefault block_size fails unless the user repeats that flag. The documented run saves block_size=128, but a restart defaults to 256. The model uses the saved value while TokenData uses the default, so the context-length check aborts. Restore block_size from the checkpoint before creating TokenData.
| if step % config["log_interval"] == 0: | ||
| if ddp: | ||
| dist.all_reduce(accumulated_loss) | ||
| loss_value = accumulated_loss.item() / world_size |
There was a problem hiding this comment.
On CUDA, accumulated_loss.item() makes the CPU wait for GPU work during logging. Evaluation does the same with total.item(). Sampling copies generated tokens with tolist(), and muon_hyperball setup compares a CUDA norm with zero.
The repository requires all device-to-host synchronizations to be flagged as high priority, including logging and inference. Avoid unnecessary waits and batch the required output transfers before merging.
Rule Used: Always flag device-to-host synchronizations (e.g., comparing a CUDA tensor to a Python scalar, .item() calls, or any operation that moves data from GPU to CPU) as high priority issues, regardless of context (training loops, inference, distributed o... (source)
| if FLAGS.data_dir: | ||
| with (Path(FLAGS.data_dir) / "meta.pkl").open("rb") as stream: | ||
| meta = pickle.load(stream) | ||
| if "stoi" in meta: | ||
| encode = lambda text: [meta["stoi"][char] for char in text] | ||
| decode = lambda tokens: "".join(meta["itos"][token] for token in tokens) |
There was a problem hiding this comment.
Character mapping breaks GPT-2 sampling
--init_from=gpt2 --data_dir=/tmp/shakespeare_char loads GPT-2 but encodes prompts with character IDs. Those IDs mean different things to GPT-2. Decoding a generated ID absent from itos also raises KeyError.
Reject character metadata for direct GPT-2 sampling, and check metadata against the loaded model before using it.
Signed-off-by: Hao Wu <skyw@nvidia.com>
No description provided.