Dataset Viewer
text
stringlengths 0
194
|
---|
[2025-06-04 06:10:46] [Rank 0] PRINT: --- Script Start: Wed Jun 4 06:10:46 2025 --- |
[2025-06-04 06:10:46] [Rank 0] PRINT: --- Script Start: Wed Jun 4 06:10:46 2025 --- |
[2025-06-04 06:10:46] [Rank 0] PRINT: Parsed CLI args: Namespace(unet=False, seed=42, optimizer_mode=0, model_parameterization='qkvo') |
[2025-06-04 06:10:46] [Rank 0] PRINT: Parsed CLI args: Namespace(unet=False, seed=42, optimizer_mode=0, model_parameterization='qkvo') |
[2025-06-04 06:10:46] [Rank 0] PRINT: Hyperparameters: Hyperparameters() |
[2025-06-04 06:10:46] [Rank 0] PRINT: Hyperparameters: Hyperparameters() |
[2025-06-04 06:10:46] [Rank 0] PRINT: Using fixed seed: 42 |
[2025-06-04 06:10:46] [Rank 0] PRINT: Using fixed seed: 42 |
[2025-06-04 06:10:46] [Rank 0] PRINT: Run directory: logs_qkvo/adam_lr_001/mode_0_param_qkvo_seed_42 |
[2025-06-04 06:10:46] [Rank 0] PRINT: Run directory: logs_qkvo/adam_lr_001/mode_0_param_qkvo_seed_42 |
[2025-06-04 06:10:46] [Rank 0] import os |
import sys |
with open(sys.argv[0]) as f: |
code = f.read() # read the code of this file ASAP, for logging |
import uuid |
import time |
import copy |
import glob |
from dataclasses import dataclass, asdict |
from functools import lru_cache |
from pathlib import Path |
import argparse # Keep argparse for --unet and potentially --optimizer_mode |
import json |
import random |
import numpy as np |
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True" |
import torch |
torch.empty(1, device="cuda", requires_grad=True).backward() # prevents a bug on some systems |
from torch import Tensor, nn |
import torch.nn.functional as F |
import torch.distributed as dist |
# use of FlexAttention contributed by @KoszarskyB |
from torch.nn.attention.flex_attention import BlockMask, flex_attention |
sys.path.append("/home/aiops/zhangfz/MUON_theory/modded-nanogpt") # Already present |
from optimizers.MUON import Muon |
from utils.float_compute import mm_op, backward as mm_backward_custom, setup_context as mm_setup_context_custom # Renamed |
#from kn_util.utils import setup_debugpy |
#torch._inductor.config.coordinate_descent_tuning = True |
# ----------------------------------------------------------------------------- |
mm_op.register_autograd(mm_backward_custom, setup_context=mm_setup_context_custom) # Use renamed imports |
# ----------------------------------------------------------------------------- |
# Seeding Function |
def set_seed(seed): |
random.seed(seed) |
np.random.seed(seed) |
torch.manual_seed(seed) |
if torch.cuda.is_available(): |
torch.cuda.manual_seed_all(seed) |
print(f"PRINT: Set seed to {seed}", flush=True) # Print immediately for all ranks |
# ----------------------------------------------------------------------------- |
# Our own simple Distributed Data Loader (KEEP AS IS) |
def _load_data_shard(file: Path): |
header = torch.from_file(str(file), False, 256, dtype=torch.int32) |
assert header[0] == 20240520, "magic number mismatch in the data .bin file" |
assert header[1] == 1, "unsupported version" |
num_tokens = int(header[2]) |
with file.open("rb", buffering=0) as f: |
tokens = torch.empty(num_tokens, dtype=torch.uint16, pin_memory=True) |
f.seek(256 * 4) |
nbytes = f.readinto(tokens.numpy()) |
assert nbytes == 2 * num_tokens, "number of tokens read does not match header" |
return tokens |
def distributed_data_generator(filename_pattern: str, batch_size: int, rank : int, world_size : int): |
files = [Path(file) for file in sorted(glob.glob(filename_pattern))] |
assert batch_size % world_size == 0 |
local_batch_size = batch_size // world_size |
file_iter = iter(files) # use itertools.cycle(files) instead if you want to do multi-epoch training |
tokens, pos = _load_data_shard(next(file_iter)), 0 |
while True: |
if pos + batch_size + 1 >= len(tokens): |
tokens, pos = _load_data_shard(next(file_iter)), 0 |
buf = tokens[pos + rank * local_batch_size:][:local_batch_size + 1] |
inputs = buf[:-1].to(device="cuda", dtype=torch.int32, non_blocking=True) # no sync on host side; |
targets = buf[1:].to(device="cuda", dtype=torch.int64, non_blocking=True) # H2D in another stream isn't helpful. |
pos += batch_size |
yield inputs, targets |
# ----------------------------------------------------------------------------- |
# int main |
parser = argparse.ArgumentParser(description="NanoGPT Training Script with Muon") |
parser.add_argument("--unet", action="store_true", help="Use U-net architecture") |
parser.add_argument("--seed", type=int, default=42, help="Random seed for reproducibility") |
# --- MODIFICATION: Add optimizer_mode as a CLI argument --- |
parser.add_argument("--optimizer_mode", type=int, default=0, |
help="Defines how Muon is applied. " |
"0: Muon(All Hidden Attn+MLP - original); " |
"1: Muon(QK Attn)/Adam(VO Attn,MLP); " |
"2: Muon(VO Attn)/Adam(QK Attn,MLP); " |
"3: Muon(All Attn)/Adam(MLP); " |
"4: Muon(MLP)/Adam(All Attn)" |
"5: All Adam (No Muon, all applicable matrices to Adam)." |
"6: Muon(W_2 MLP)/Adam(attn, W_1 MLP)." |
End of preview. Expand
in Data Studio
No dataset card yet
- Downloads last month
- 102