path
stringlengths
9
117
type
stringclasses
2 values
project
stringclasses
10 values
commit_hash
stringlengths
40
40
commit_message
stringlengths
1
137
ground_truth
stringlengths
0
2.74k
main_code
stringlengths
102
3.37k
context
stringlengths
0
14.7k
RWKV-v4neo.src.dataset/MyDataset.__init__
Modified
BlinkDL~RWKV-LM
1945cb58ed29ed1c353453bb93a7ee72d563d3bc
pile v2
<6>:<del> if args.data_file.endswith('/'): <7>:<del> d_all = [] <8>:<del> for p in os.listdir(args.data_file): <9>:<del> if p.endswith(".idx"): <10>:<del> d_all += [p[:-4]] <11>:<del> d_all.sort() <12>:<del> ...
# module: RWKV-v4neo.src.dataset class MyDataset(Dataset): def __init__(self, args): <0> self.args = args <1> <2> if args.data_type == "binidx": <3> self.vocab_size = args.vocab_size <4> rank_zero_info(f"Current vocab size = {self.vocab_size} (mak...
===========below chunk 0=========== # module: RWKV-v4neo.src.dataset class MyDataset(Dataset): def __init__(self, args): # offset: 1 assert args.magic_prime / dataset_slot > 0.99 and args.magic_prime / dataset_slot <= 1 elif args.data_type == "numpy": ...
RWKV-v4neo.src.dataset/MyDataset.__init__
Modified
BlinkDL~RWKV-LM
79915b3696fc744d410b69a09510b7161bda835b
better
<24>:<add> self.data_pile = MMapIndexedDataset('/fsx/pile/pile_20B_tokenizer_text_document') <del> self.data_pile = MMapIndexedDataset('/fsx/BlinkDL/pile/pile_20B_tokenizer_text_document') <25>:<add> # self.data_pile = MMapIndexedDataset('/fsx/pile_deduped/pile_0.87_...
# module: RWKV-v4neo.src.dataset class MyDataset(Dataset): def __init__(self, args): <0> self.args = args <1> <2> if args.data_type == "binidx": <3> self.vocab_size = args.vocab_size <4> rank_zero_info(f"Current vocab size = {self.vocab_size} (mak...
===========below chunk 0=========== # module: RWKV-v4neo.src.dataset class MyDataset(Dataset): def __init__(self, args): # offset: 1 # assert self.data_size == 332115325534 and self.vocab_size == 50277 self.samples_per_epoch = args.epoch_steps * args.real_bsz ...
RWKV-v4neo.src.dataset/MyDataset.__init__
Modified
BlinkDL~RWKV-LM
725327d667167a23ce6100e7d4c7b6fb9d6b1a40
Merge branch 'main' of https://github.com/BlinkDL/RWKV-LM into main
<24>:<add> # self.data_pile = MMapIndexedDataset('/fsx/pile/pile_20B_tokenizer_text_document') <del> self.data_pile = MMapIndexedDataset('/fsx/pile/pile_20B_tokenizer_text_document') <25>:<add> self.data_pile = MMapIndexedDataset('/fsx/pile_deduped/pile_0.87_deduped_...
# module: RWKV-v4neo.src.dataset class MyDataset(Dataset): def __init__(self, args): <0> self.args = args <1> <2> if args.data_type == "binidx": <3> self.vocab_size = args.vocab_size <4> rank_zero_info(f"Current vocab size = {self.vocab_size} (mak...
===========below chunk 0=========== # module: RWKV-v4neo.src.dataset class MyDataset(Dataset): def __init__(self, args): # offset: 1 if args.my_pile_stage > 0: # assert self.data_size == 332115325534 and self.vocab_size == 50277 self.sampl...
RWKV-v4neo.src.trainer/train_callback.on_train_batch_start
Modified
BlinkDL~RWKV-LM
725327d667167a23ce6100e7d4c7b6fb9d6b1a40
Merge branch 'main' of https://github.com/BlinkDL/RWKV-LM into main
<9>:<add> if trainer.global_step < w_step: <add> lr = lr * (0.2 + 0.8 * trainer.global_step / w_step)
# module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_start(self, trainer, pl_module, batch, batch_idx): <0> args = self.args <1> # if args.cuda_cleanup > 0: <2> # torch.cuda.empty_cache() <3> real_step = trainer.global_s...
===========below chunk 0=========== # module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_start(self, trainer, pl_module, batch, batch_idx): # offset: 1 else: param_group["lr"] = lr trainer.my_lr = lr #...
RWKV-v4neo.src.trainer/train_callback.on_train_batch_end
Modified
BlinkDL~RWKV-LM
a8ec3151b6e2160b9c46527a71ccc6f47b5125df
fix
# module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_end(self, trainer, pl_module, outputs, batch, batch_idx): <0> args = self.args <1> if trainer.is_global_zero: # logging <2> t_now = time.time_ns() <3> token_per_s...
===========below chunk 0=========== # module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_end(self, trainer, pl_module, outputs, batch, batch_idx): # offset: 1 trainer.my_wandb.log(lll, step=int(real_step)) if args.magic_prime > 0:...
RWKV-v4neo.src.trainer/train_callback.on_train_epoch_end
Modified
BlinkDL~RWKV-LM
2f57660839017c3a3138cd2199df3232bf3a9a8c
misc
<2>:<add> if (args.epoch_save > 0 and trainer.current_epoch % args.epoch_save == 0) or (trainer.current_epoch == args.epoch_count - 1): <del> if (args.epoch_save > 0 and trainer.current_epoch % args.epoch_save == 0) or trainer.current_epoch == args.epoch_count - 1: <23>:<add> i...
# module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): # print(f'########## world_size {dataset.world_size} global_rank {dataset.global_rank} real_epoch {dataset.real_epoch} ##########') def on_train_epoch_end(self, trainer, pl_module): <0> args = self.a...
===========unchanged ref 0=========== at: RWKV-v4neo.src.trainer my_save(dd, ff) at: RWKV-v4neo.src.trainer.train_callback.__init__ self.args = args at: datetime datetime() at: datetime.datetime __slots__ = date.__slots__ + time.__slots__ now(t...
RWKV-v4neo.src.dataset/MyDataset.__init__
Modified
BlinkDL~RWKV-LM
f8c5f6c3dea1d720c5774fb0352bee373e3bc244
misc
<10>:<add> elif args.my_pile_version == 2: <del> else:
# module: RWKV-v4neo.src.dataset class MyDataset(Dataset): def __init__(self, args): <0> self.args = args <1> <2> if args.data_type == "binidx": <3> self.vocab_size = args.vocab_size <4> rank_zero_info(f"Current vocab size = {self.vocab_size} (mak...
===========below chunk 0=========== # module: RWKV-v4neo.src.dataset class MyDataset(Dataset): def __init__(self, args): # offset: 1 else: self.data_pile = None self.data_pile_size = 0 if args.my_pile_stage > 0: ...
RWKV-v4neo.src.trainer/my_save
Modified
BlinkDL~RWKV-LM
f8c5f6c3dea1d720c5774fb0352bee373e3bc244
misc
<0>:<add> if '14b-run1' in ff: <del> if '14b-run1' not in ff: <1>:<del> torch.save(dd, ff) <2>:<del> else: <7>:<add> elif ('world/14b' in ff) or ('world/7b' in ff): <add> aa = ff.split('/')[1] <add> fn = ff.split('/')[-1] <add> fff = f'/dev/shm/{aa...
# module: RWKV-v4neo.src.trainer def my_save(dd, ff): <0> if '14b-run1' not in ff: <1> torch.save(dd, ff) <2> else: <3> fn = ff.split('/')[-1] <4> fff = '/dev/shm/' + fn <5> torch.save(dd, fff) <6> subprocess.Popen(f" aws s3 mv {fff} s3://rwkv-14...
===========unchanged ref 0=========== at: subprocess Popen() at: torch.serialization save(obj: object, f: FILE_LIKE, pickle_module: Any=pickle, pickle_protocol: int=DEFAULT_PROTOCOL, _use_new_zipfile_serialization: bool=True, _disable_byteorder_record: bool=False) -> None ========...
RWKV-v4neo.src.dataset/MyDataset.__init__
Modified
BlinkDL~RWKV-LM
cca1b5e8e597cf40675882bb10b46287c844e35c
misc
# module: RWKV-v4neo.src.dataset class MyDataset(Dataset): def __init__(self, args): <0> self.args = args <1> <2> if args.data_type == "binidx": <3> self.vocab_size = args.vocab_size <4> rank_zero_info(f"Current vocab size = {self.vocab_size} (mak...
===========below chunk 0=========== # module: RWKV-v4neo.src.dataset class MyDataset(Dataset): def __init__(self, args): # offset: 1 else: self.data_pile = None self.data_pile_size = 0 if args.my_pile_stage > 0: ...
RWKV-v4neo.src.trainer/train_callback.on_train_batch_start
Modified
BlinkDL~RWKV-LM
cca1b5e8e597cf40675882bb10b46287c844e35c
misc
<26>:<add> <add> if args.my_exit_tokens > 0: # cosine decay <add> if trainer.global_step < w_step: <add> lr = args.lr_init * (0.2 + 0.8 * trainer.global_step / w_step) <add> else: <add> real_tokens = real_step * args.ctx_len * arg...
# module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_start(self, trainer, pl_module, batch, batch_idx): <0> args = self.args <1> # if args.cuda_cleanup > 0: <2> # torch.cuda.empty_cache() <3> real_step = trainer.global_s...
===========below chunk 0=========== # module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_start(self, trainer, pl_module, batch, batch_idx): # offset: 1 if args.layerwise_lr > 0: param_group["lr"] = lr * param_group["my_lr_scale"] ...
RWKV-v4neo.src.model/RWKV.configure_optimizers
Modified
BlinkDL~RWKV-LM
a637aea61c77cedd290054449d819da5e7b19d44
weight decay (very important for small dataset)
<1>:<add> <add> lr_decay = set() <del> if args.layerwise_lr > 0: <2>:<add> lr_1x = set() <del> lr_1x = set() <3>:<add> lr_2x = set() <del> lr_2x = set() <4>:<add> lr_3x = set() <del> lr_3x = set() <5>:<add...
# module: RWKV-v4neo.src.model class RWKV(pl.LightningModule): def configure_optimizers(self): <0> args = self.args <1> if args.layerwise_lr > 0: <2> lr_1x = set() <3> lr_2x = set() <4> lr_3x = set() <5> for n, p in self.n...
===========below chunk 0=========== # module: RWKV-v4neo.src.model class RWKV(pl.LightningModule): def configure_optimizers(self): # offset: 1 ] else: optim_groups = [ {"params": [param_dict[n] for n in lr_1x], "weight_d...
RWKV-v4neo.src.model/Block.__init__
Modified
BlinkDL~RWKV-LM
9143748f8079e7d3c726c2b98a83681242da30f7
RWKV5 preview
<16>:<add> if 'r' in os.environ["RWKV_MY_TESTING"]: <add> self.att = RWKV_TimeMix_RWKV5_Preview(args, layer_id) <add> else: <add> self.att = RWKV_TimeMix(args, layer_id) <del> self.att = RWKV_TimeMix(args, layer_id)
# module: RWKV-v4neo.src.model ######################################################################################################## # The RWKV Model with our blocks ######################################################################################################## cl...
===========below chunk 0=========== # module: RWKV-v4neo.src.model ######################################################################################################## # The RWKV Model with our blocks ###################################################################################################...
RWKV-v4neo.src.model/RWKV.generate_init_weight
Modified
BlinkDL~RWKV-LM
9143748f8079e7d3c726c2b98a83681242da30f7
RWKV5 preview
<24>:<add> if 'r' in os.environ["RWKV_MY_TESTING"]: <add> zero = [".att.output.", ".ffn.value.", ".ffn.receptance.", ".ffnPre.value.", ".ffnPre.receptance.", "head_q.", '.oo.', '.rr.'] <add> else: <add> zero = [".att....
# module: RWKV-v4neo.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): <0> print( <1> f""" <2> ############################################################################ <3> # <4> # Init model weight (slow for large models)... <5> # <6> #...
===========below chunk 0=========== # module: RWKV-v4neo.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): # offset: 1 m[n] = torch.empty((shape[0], shape[1])) if scale == 0: nn.init.zeros_(m[n]) ...
RWKV-v4neo.src.model/RWKV_TimeMix_RWKV5_Preview.__init__
Modified
BlinkDL~RWKV-LM
686c962008676809f17cf2424c193d9dc217c0e4
rwkv5 with time_first
<6>:<add> self.head_size = 64 <del> try: <7>:<add> self.n_head = self.n_embd // self.head_size <del> self.n_head = self.n_embd // 96 <8>:<add> assert self.n_embd % self.n_head == 0 <del> assert self.n_embd % self.n_head == 0 <9>:<add> <add...
# module: RWKV-v4neo.src.model ######################################################################################################## + class RWKV_TimeMix_RWKV5_Preview(MyModule): - class RWKV_TimeMix_RWKV5_Preview(nn.Module): def __init__(self, args, layer_id): <0> supe...
===========below chunk 0=========== # module: RWKV-v4neo.src.model ######################################################################################################## + class RWKV_TimeMix_RWKV5_Preview(MyModule): - class RWKV_TimeMix_RWKV5_Preview(nn.Module): def __init__(self, args, layer...
RWKV-v4neo.src.model/RWKV_TimeMix_RWKV5_Preview.forward
Modified
BlinkDL~RWKV-LM
686c962008676809f17cf2424c193d9dc217c0e4
rwkv5 with time_first
<0>:<del> B, TT, C = x.size() # x = (Batch,Time,Channel) <2>:<add> T = self.chunk_len <del> S = self.head_size <4>:<del> xx = self.time_shift(x) # Mix x with the previous timestep to produce xk, xv, xr <5>:<del> xk = x * self.time_mix_k + xx * (1 - self.time_mix_k) <6>...
# module: RWKV-v4neo.src.model ######################################################################################################## + class RWKV_TimeMix_RWKV5_Preview(MyModule): - class RWKV_TimeMix_RWKV5_Preview(nn.Module): + def forward(self, x): <0> B, TT, ...
===========below chunk 0=========== # module: RWKV-v4neo.src.model ######################################################################################################## + class RWKV_TimeMix_RWKV5_Preview(MyModule): - class RWKV_TimeMix_RWKV5_Preview(nn.Module): + def forward(self, x):...
RWKV-v4neo.src.model/RWKV_TimeMix_RWKV5_Preview.__init__
Modified
BlinkDL~RWKV-LM
9b38a54c8e9e0cdc01e3d461a299485d3c1be6c3
BUG FIX: rwkv5 groupnorm was wrong
<28>:<add> decay_speed[h] = -10 + 9 * (h / (self.n_head - 1)) ** (0.7 + 1.3 * ratio_0_to_1) <del> decay_speed[h] = -9 + 8 * (h / (self.
# module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5_Preview(MyModule): def __init__(self, args, layer_id): <0> super().__init__() <1> self.args = args <2> ...
===========below chunk 0=========== # module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5_Preview(MyModule): def __init__(self, args, layer_id): # offset: 1 self.time_d...
RWKV-v4neo.src.model/RWKV_TimeMix_RWKV5_Preview.jit_func_2
Modified
BlinkDL~RWKV-LM
9b38a54c8e9e0cdc01e3d461a299485d3c1be6c3
BUG FIX: rwkv5 groupnorm was wrong
<19>:<add> x = x.transpose(1, 2).contiguous().view(B * TT, H*S) # BHTS -> BTHS -> BTC <del> x = x.transpose(1, 2).contiguous().view(B, TT, H*S) # BHTS -> BTHS -> BTC <20>:<add> x = self.ln_x(x).view(B, TT, H*S) <del> x = self.ln_x(x.transpose(-2, -1)).transpose(-2, -1)
# module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5_Preview(MyModule): @MyFunction def jit_func_2(self, r, k, v, w, wk, wb, ws): <0> B, H, TT, S = r.size() ...
===========unchanged ref 0=========== at: RWKV-v4neo.src.model.RWKV_TimeMix_RWKV5_Preview.__init__ self.chunk_len = 512 ===========changed ref 0=========== # module: RWKV-v4neo.src.model #######################################################################################################...
RWKV-v4neo.src.model/RWKV_TimeMix_RWKV5_Preview.__init__
Modified
BlinkDL~RWKV-LM
468e608107632743c5ea3a9c23d9a18b4ee2ab59
rwkv5 working
<28>:<add> decay_speed[h] = -8 + 7 * (h / (self.n_head - 1)) ** (0.7 + 1.3 * ratio_0_to_1) <del> decay_speed[h] = -10 + 9 * (h / (self.
# module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5_Preview(MyModule): def __init__(self, args, layer_id): <0> super().__init__() <1> self.args = args <2> ...
===========below chunk 0=========== # module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5_Preview(MyModule): def __init__(self, args, layer_id): # offset: 1 self.time_d...
RWKV-v4neo.src.model/RWKV.generate_init_weight
Modified
BlinkDL~RWKV-LM
bff997a64972a343ccc40afffdb850c4a89c6b56
better rwkv5
<17>:<add> if 'ln_x.weight' in n: <add> layer_scale = (1+int(n.split('.')[1])) / self.args.n_layer <add> m[n] = (p * 0.0) + (layer_scale ** 0.5) <add> else: <add> m[n] = p <del> m[n] = p
# module: RWKV-v4neo.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): <0> print( <1> f""" <2> ############################################################################ <3> # <4> # Init model weight (slow for large models)... <5> # <6> #...
===========below chunk 0=========== # module: RWKV-v4neo.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): # offset: 1 if self.args.accelerator.upper() == "GPU": m[n] = torch.empty((shape[0], shape[1]), device="cuda") ...
RWKV-v4neo.src.model/RWKV_TimeMix_RWKV5_Preview.__init__
Modified
BlinkDL~RWKV-LM
69e6c50001e8da742dcfdd7e53064f155a6c9ad1
Merge branch 'main' of https://github.com/BlinkDL/RWKV-LM into main
# module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5_Preview(MyModule): def __init__(self, args, layer_id): <0> super().__init__() <1> self.args = args <2> ...
===========below chunk 0=========== # module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5_Preview(MyModule): def __init__(self, args, layer_id): # offset: 1 self.time_d...
RWKV-v4neo.src.model/RWKV_TimeMix_RWKV5_Preview.forward
Modified
BlinkDL~RWKV-LM
69e6c50001e8da742dcfdd7e53064f155a6c9ad1
Merge branch 'main' of https://github.com/BlinkDL/RWKV-LM into main
<6>:<add> <add> if 'r2' in os.environ["RWKV_MY_TESTING"]: <add> u = self.time_faaaa.float().unsqueeze(-1) <add> else: <add> u = torch.exp(self.time_first.float()).unsqueeze(-1) <del> u = torch.exp(self.time_first.float()).unsqueeze(-1)
# module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5_Preview(MyModule): def forward(self, x): <0> H = self.n_head <1> T = self.chunk_len <2> <...
===========unchanged ref 0=========== at: RWKV-v4neo.src.model.RWKV_TimeMix_RWKV5_Preview.__init__ self.n_head = self.n_embd // self.head_size self.chunk_len = 512 self.time_decay = nn.Parameter(decay_speed) self.time_faaaa = nn.Parameter(torch.ones(self.n_head) * 0.05...
RWKV-v4neo.src.model/RWKV.configure_optimizers
Modified
BlinkDL~RWKV-LM
69e6c50001e8da742dcfdd7e53064f155a6c9ad1
Merge branch 'main' of https://github.com/BlinkDL/RWKV-LM into main
<13>:<add> if args.my_pile_stage == 2: <add> lr_3x.add(n) <add> else: <add> lr_2x.add(n) <add> elif ("time_faaaa" in n) and (args.layerwise_lr > 0):
# module: RWKV-v4neo.src.model class RWKV(pl.LightningModule): def configure_optimizers(self): <0> args = self.args <1> <2> lr_decay = set() <3> lr_1x = set() <4> lr_2x = set() <5> lr_3x = set() <6> for n, p in self.named_param...
===========below chunk 0=========== # module: RWKV-v4neo.src.model class RWKV(pl.LightningModule): def configure_optimizers(self): # offset: 1 {"params": [param_dict[n] for n in lr_2x], "weight_decay": 0.0, "my_lr_scale": 5.0},# test: 2e-3 / args.lr_init}, ...
RWKV-v4neo.src.trainer/train_callback.on_train_batch_start
Modified
BlinkDL~RWKV-LM
69e6c50001e8da742dcfdd7e53064f155a6c9ad1
Merge branch 'main' of https://github.com/BlinkDL/RWKV-LM into main
<27>:<add> if args.my_exit_tokens != 0: # cosine decay <del> if args.my_exit_tokens > 0: # cosine decay
# module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_start(self, trainer, pl_module, batch, batch_idx): <0> args = self.args <1> # if args.cuda_cleanup > 0: <2> # torch.cuda.empty_cache() <3> real_step = trainer.global_s...
===========below chunk 0=========== # module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_start(self, trainer, pl_module, batch, batch_idx): # offset: 1 lr = args.lr_init * (0.2 + 0.8 * trainer.global_step / w_step) else: ...
RWKV-v4neo.src.trainer/train_callback.on_train_batch_end
Modified
BlinkDL~RWKV-LM
69e6c50001e8da742dcfdd7e53064f155a6c9ad1
Merge branch 'main' of https://github.com/BlinkDL/RWKV-LM into main
<23>:<add> lll = {"loss": trainer.my_loss, "lr": trainer.my_lr, "wd": trainer.my_wd, "Gtokens": real_step * token_per_step / 1e9} <del> lll = {"loss": trainer.my_loss, "lr": trainer.my_lr, "Gtokens": real_step * token_per_step / 1e9}
# module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_end(self, trainer, pl_module, outputs, batch, batch_idx): <0> args = self.args <1> if trainer.is_global_zero: # logging <2> t_now = time.time_ns() <3> token_per_s...
===========below chunk 0=========== # module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_end(self, trainer, pl_module, outputs, batch, batch_idx): # offset: 1 trainer.my_wandb.log(lll, step=int(real_step)) if args.magic_prime > 0:...
RWKV-v4neo.src.trainer/generate_init_weight
Modified
BlinkDL~RWKV-LM
69e6c50001e8da742dcfdd7e53064f155a6c9ad1
Merge branch 'main' of https://github.com/BlinkDL/RWKV-LM into main
<7>:<add> try: <add> assert k in mm <del> assert k in mm <8>:<add> except: <add> print('missing', k) <add> exit(0)
# module: RWKV-v4neo.src.trainer @rank_zero_only def generate_init_weight(model, init_weight_name): <0> mm = model.generate_init_weight() <1> <2> if model.args.my_pile_stage == 1: <3> if len(model.args.load_model) > 0: <4> print(f"Combine weights from {model.args...
===========below chunk 0=========== # module: RWKV-v4neo.src.trainer @rank_zero_only def generate_init_weight(model, init_weight_name): # offset: 1 ===========unchanged ref 0=========== at: RWKV-v4neo.src.trainer.train_callback.on_train_epoch_end args = self.args at: datet...
RWKV-v4neo.src.model/Block.forward
Modified
BlinkDL~RWKV-LM
b42fc101f8b8ffdee4128ac5ba6ee938d6273258
+ dropout
<8>:<add> if self.args.dropout == 0: <add> if self.layer_id == 0 and args.pre_ffn > 0: <del> if self.layer_id == 0 and args.pre_ffn > 0: <9>:<add> x = x + self.ffnPre(self.ln1(x)) <del> x = x + self.ffnPre(self.ln1(x)) <10>:<add> else:...
# module: RWKV-v4neo.src.model ######################################################################################################## # The RWKV Model with our blocks ######################################################################################################## cl...
RWKV-v4neo.src.model/RWKV.__init__
Modified
BlinkDL~RWKV-LM
b42fc101f8b8ffdee4128ac5ba6ee938d6273258
+ dropout
<22>:<add> if args.dropout > 0: <add> self.drop0 = nn.Dropout(p = args.dropout)
# module: RWKV-v4neo.src.model class RWKV(pl.LightningModule): def __init__(self, args): <0> super().__init__() <1> self.args = args <2> if not hasattr(args, 'dim_att'): <3> args.dim_att = args.n_embd <4> if not hasattr(args, 'dim_ffn'): <5> ...
===========changed ref 0=========== # module: RWKV-v4neo.src.model ######################################################################################################## # The RWKV Model with our blocks ###################################################################################################...
RWKV-v4neo.src.model/RWKV.forward
Modified
BlinkDL~RWKV-LM
b42fc101f8b8ffdee4128ac5ba6ee938d6273258
+ dropout
<7>:<add> if args.dropout > 0: <add> x = self.drop0(x)
# module: RWKV-v4neo.src.model class RWKV(pl.LightningModule): def forward(self, idx): <0> args = self.args <1> B, T = idx.size() <2> assert T <= args.ctx_len, "Cannot forward, model ctx_len is exhausted." <3> <4> x = self.emb(idx) <5> x_emb = x...
===========below chunk 0=========== # module: RWKV-v4neo.src.model class RWKV(pl.LightningModule): def forward(self, idx): # offset: 1 else: x = self.head(x) return x ===========changed ref 0=========== # module: RWKV-v4neo.src.model cla...
RWKV-v4neo.src.model/RWKV.training_step_end
Modified
BlinkDL~RWKV-LM
087a66accf9bd698d651b5609bfad42cfca0cd69
增加PyTorch Lightning 2.0支持
<0>:<add> if pl.__version__[0]!='2': <add> all = self.all_gather(batch_parts) <del> all = self.all_gather(batch_parts) <1>:<add> if self.trainer.is_global_zero: <del> if self.trainer.is_global_zero: <2>:<add> self.trainer.my_loss_all = al...
# module: RWKV-v4neo.src.model class RWKV(pl.LightningModule): def training_step_end(self, batch_parts): <0> all = self.all_gather(batch_parts) <1> if self.trainer.is_global_zero: <2> self.trainer.my_loss_all = all <3>
===========changed ref 0=========== # module: RWKV-v4neo.train logging.basicConfig(level=logging.INFO) if __name__ == "__main__": from argparse import ArgumentParser from pytorch_lightning import Trainer from pytorch_lightning.utilities import rank_zero_info, rank_zero_only + ...
RWKV-v4neo.src.trainer/train_callback.on_train_batch_end
Modified
BlinkDL~RWKV-LM
087a66accf9bd698d651b5609bfad42cfca0cd69
增加PyTorch Lightning 2.0支持
<14>:<add> if pl.__version__[0]=='2': <add> trainer.my_loss = outputs["loss"] <add> else: <add> trainer.my_loss = trainer.my_loss_all.float().mean().item() <del> trainer.my_loss = trainer.my_loss_all.float().mean().item()
# module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_end(self, trainer, pl_module, outputs, batch, batch_idx): <0> args = self.args <1> if trainer.is_global_zero: # logging <2> t_now = time.time_ns() <3> token_per_s...
===========below chunk 0=========== # module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_end(self, trainer, pl_module, outputs, batch, batch_idx): # offset: 1 lll["kt/s"] = kt_s trainer.my_wandb.log(lll, step=int(real_step...
RWKV-v4neo.src.trainer/train_callback.on_train_epoch_start
Modified
BlinkDL~RWKV-LM
087a66accf9bd698d651b5609bfad42cfca0cd69
增加PyTorch Lightning 2.0支持
<1>:<add> if pl.__version__[0]=='2': <add> dataset = trainer.train_dataloader.dataset <add> else: <add> dataset = trainer.train_dataloader.dataset.datasets <del> dataset = trainer.train_dataloader.dataset.datasets
# module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_epoch_start(self, trainer, pl_module): <0> args = self.args <1> dataset = trainer.train_dataloader.dataset.datasets <2> assert "MyDataset" in str(dataset) <...
===========unchanged ref 0=========== at: RWKV-v4neo.src.trainer.train_callback.__init__ self.args = args at: RWKV-v4neo.src.trainer.train_callback.on_train_batch_end args = self.args to_save_dict = pl_module.state_dict() ===========changed ref 0=========== # modu...
RWKV-v4neo.src.dataset/MyDataset.__init__
Modified
BlinkDL~RWKV-LM
673d241cdaaf54cb927f49e2a2ca4542b3d98fab
Merge pull request #178 from fluxlinkage/main
# module: RWKV-v4neo.src.dataset class MyDataset(Dataset): def __init__(self, args): <0> self.args = args <1> <2> if args.data_type == "binidx": <3> self.vocab_size = args.vocab_size <4> rank_zero_info(f"Current vocab size = {self.vocab_size} (mak...
===========below chunk 0=========== # module: RWKV-v4neo.src.dataset class MyDataset(Dataset): def __init__(self, args): # offset: 1 else: self.data_pile = None self.data_pile_size = 0 if args.my_pile_stage > 0: ...
RWKV-v4neo.src.trainer/my_save
Modified
BlinkDL~RWKV-LM
673d241cdaaf54cb927f49e2a2ca4542b3d98fab
Merge pull request #178 from fluxlinkage/main
<12>:<add> if 'deepspeed_stage_3' in args.strategy: <add> trainer.save_checkpoint(ff, weights_only=True) <add> else: <add> torch.save(dd, ff) <del> torch.save(dd, ff)
# module: RWKV-v4neo.src.trainer + def my_save(args, trainer, dd, ff): - def my_save(dd, ff): <0> if '14b-run1' in ff: <1> fn = ff.split('/')[-1] <2> fff = '/dev/shm/' + fn <3> torch.save(dd, fff) <4> subprocess.Popen(f" aws s3 mv {fff} s3://rwkv-14b-4k/{fn} -...
===========unchanged ref 0=========== at: subprocess Popen() at: torch.serialization save(obj: object, f: FILE_LIKE, pickle_module: Any=pickle, pickle_protocol: int=DEFAULT_PROTOCOL, _use_new_zipfile_serialization: bool=True, _disable_byteorder_record: bool=False) -> None ========...
RWKV-v4neo.src.trainer/train_callback.on_train_batch_start
Modified
BlinkDL~RWKV-LM
673d241cdaaf54cb927f49e2a2ca4542b3d98fab
Merge pull request #178 from fluxlinkage/main
# module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_start(self, trainer, pl_module, batch, batch_idx): <0> args = self.args <1> # if args.cuda_cleanup > 0: <2> # torch.cuda.empty_cache() <3> real_step = trainer.global_s...
===========below chunk 0=========== # module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_start(self, trainer, pl_module, batch, batch_idx): # offset: 1 lr = args.lr_init * (0.2 + 0.8 * trainer.global_step / w_step) else: ...
RWKV-v4neo.src.trainer/train_callback.on_train_batch_end
Modified
BlinkDL~RWKV-LM
673d241cdaaf54cb927f49e2a2ca4542b3d98fab
Merge pull request #178 from fluxlinkage/main
<1>:<add> token_per_step = args.ctx_len * args.real_bsz <add> real_step = trainer.global_step + args.epoch_begin * args.epoch_steps <3>:<del> token_per_step = args.ctx_len * args.real_bsz <4>:<del> real_step = trainer.global_step + args.epoch_begin * args.epoch_steps
# module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_end(self, trainer, pl_module, outputs, batch, batch_idx): <0> args = self.args <1> if trainer.is_global_zero: # logging <2> t_now = time.time_ns() <3> token_per_s...
===========below chunk 0=========== # module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_end(self, trainer, pl_module, outputs, batch, batch_idx): # offset: 1 if kt_s > 0: lll["kt/s"] = kt_s trainer.my_...
RWKV-v4neo.src.trainer/train_callback.on_train_epoch_end
Modified
BlinkDL~RWKV-LM
673d241cdaaf54cb927f49e2a2ca4542b3d98fab
Merge pull request #178 from fluxlinkage/main
<1>:<add> to_save_dict = {} <add> if (trainer.is_global_zero) or ('deepspeed_stage_3' in args.strategy): # save pth <del> if trainer.is_global_zero: # logging & save state_dict <5>:<del> to_save_dict = {} <13>:<add> args, trainer, <18>:<a...
# module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): # print(f'########## world_size {dataset.world_size} global_rank {dataset.global_rank} real_epoch {dataset.real_epoch} ##########') def on_train_epoch_end(self, trainer, pl_module): <0> args = self.a...
===========unchanged ref 0=========== at: RWKV-v4neo.src.trainer my_save(args, trainer, dd, ff) at: RWKV-v4neo.src.trainer.train_callback.__init__ self.args = args at: RWKV-v4neo.src.trainer.train_callback.on_train_epoch_start args = self.args ===========changed r...
RWKV-v4neo.src.model/RUN_CUDA
Modified
BlinkDL~RWKV-LM
673d241cdaaf54cb927f49e2a2ca4542b3d98fab
Merge pull request #178 from fluxlinkage/main
<0>:<add> return WKV_5.apply(B, T, C, H, r, k, v, w, u) <del> return WKV.apply(B, T, C, w, u, k, v)
# module: RWKV-v4neo.src.model + def RUN_CUDA(B, T, C, H, r, k, v, w, u): - def RUN_CUDA(B, T, C, w, u, k, v): <0> return WKV.apply(B, T, C, w, u, k, v) <1>
===========changed ref 0=========== # module: RWKV-v4neo.src.trainer + def my_save(args, trainer, dd, ff): - def my_save(dd, ff): if '14b-run1' in ff: fn = ff.split('/')[-1] fff = '/dev/shm/' + fn torch.save(dd, fff) subprocess.Popen(f" aws s3 mv {fff} s3:...
RWKV-v4neo.src.model/RWKV_TimeMix_RWKV5_Preview.__init__
Modified
BlinkDL~RWKV-LM
673d241cdaaf54cb927f49e2a2ca4542b3d98fab
Merge pull request #178 from fluxlinkage/main
<3>:<del> self.ctx_len = args.ctx_len <4>:<del> self.n_embd = args.n_embd <7>:<add> self.n_head = args.dim_att // self.head_size <del> self.n_head = self.n_embd // self.head_size <8>:<add> assert args.dim_att % self.n_head == 0 <del> assert self.n_embd % sel...
# module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5_Preview(MyModule): def __init__(self, args, layer_id): <0> super().__init__() <1> self.args = args <2> ...
===========below chunk 0=========== # module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5_Preview(MyModule): def __init__(self, args, layer_id): # offset: 1 self.time_d...
RWKV-v4neo.src.model/RWKV_TimeMix_RWKV5_Preview.jit_func_2
Modified
BlinkDL~RWKV-LM
673d241cdaaf54cb927f49e2a2ca4542b3d98fab
Merge pull request #178 from fluxlinkage/main
<0>:<add> B, H, TT, S = r.size() <del> B, H, TT, S = r.size() <1>:<add> T = self.chunk_len <del> T = self.chunk_len <3>:<add> s = torch.zeros(B, H, S, S, device=r.device, dtype=r.dtype) # state <del> s = torch.zeros(B, H, S, S, device=r.devi...
# module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5_Preview(MyModule): + @MyFunction - @MyFunction + def jit_func_2(self, r, k, v, w, wk, wb, ws): - ...
===========changed ref 0=========== # module: RWKV-v4neo.src.model + def RUN_CUDA(B, T, C, H, r, k, v, w, u): - def RUN_CUDA(B, T, C, w, u, k, v): + return WKV_5.apply(B, T, C, H, r, k, v, w, u) - return WKV.apply(B, T, C, w, u, k, v) ===========changed ref 1=========== # module: RWKV-v4neo...
RWKV-v4neo.src.model/RWKV_TimeMix_RWKV5_Preview.forward
Modified
BlinkDL~RWKV-LM
673d241cdaaf54cb927f49e2a2ca4542b3d98fab
Merge pull request #178 from fluxlinkage/main
<3>:<add> if 'r3' in os.environ["RWKV_MY_TESTING"]: <add> r, k, v, g = self.jit_func(x) <add> else: <add> r, k, v = self.jit_func(x) <del> r, k, v = self.jit_func(x) <34>:<add> if 'r3' in os.environ["RWKV_MY_TESTING"]: <add> r...
# module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5_Preview(MyModule): def forward(self, x): <0> H = self.n_head <1> T = self.chunk_len <2> <...
===========below chunk 0=========== # module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5_Preview(MyModule): def forward(self, x): # offset: 1 ===========changed ref...
RWKV-v4neo.src.model/RWKV_ChannelMix.forward
Modified
BlinkDL~RWKV-LM
673d241cdaaf54cb927f49e2a2ca4542b3d98fab
Merge pull request #178 from fluxlinkage/main
<4>:<add> k = torch.relu(k) ** 2 <del> k = torch.square(torch.relu(k))
# module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_ChannelMix(MyModule): @MyFunction def forward(self, x): <0> xx = self.time_shift(x) <1> xk = x * self.time_m...
===========changed ref 0=========== # module: RWKV-v4neo.src.model + def RUN_CUDA(B, T, C, H, r, k, v, w, u): - def RUN_CUDA(B, T, C, w, u, k, v): + return WKV_5.apply(B, T, C, H, r, k, v, w, u) - return WKV.apply(B, T, C, w, u, k, v) ===========changed ref 1=========== # module: RWKV-v4neo...
RWKV-v4neo.src.model/Block.__init__
Modified
BlinkDL~RWKV-LM
673d241cdaaf54cb927f49e2a2ca4542b3d98fab
Merge pull request #178 from fluxlinkage/main
<16>:<add> if 'r4' in os.environ["RWKV_MY_TESTING"]: <del> if 'r' in os.environ["RWKV_MY_TESTING"]: <17>:<add> self.att = RWKV_TimeMix_RWKV5(args, layer_id) <add> elif 'r' in os.environ["RWKV_MY_TESTING"]:
# module: RWKV-v4neo.src.model ######################################################################################################## # The RWKV Model with our blocks ######################################################################################################## cl...
===========below chunk 0=========== # module: RWKV-v4neo.src.model ######################################################################################################## # The RWKV Model with our blocks ###################################################################################################...
RWKV-v4neo.src.model/RWKV.__init__
Modified
BlinkDL~RWKV-LM
673d241cdaaf54cb927f49e2a2ca4542b3d98fab
Merge pull request #178 from fluxlinkage/main
<10>:<add> assert args.n_embd % 32 == 0 <add> assert args.dim_att % 32 == 0 <add> assert args.dim_ffn % 32 == 0
# module: RWKV-v4neo.src.model class RWKV(pl.LightningModule): def __init__(self, args): <0> super().__init__() <1> self.args = args <2> if not hasattr(args, 'dim_att'): <3> args.dim_att = args.n_embd <4> if not hasattr(args, 'dim_ffn'): <5> ...
===========changed ref 0=========== # module: RWKV-v4neo.src.model + ######################################################################################################## + + class RWKV_TimeMix_RWKV5(MyModule): + @MyFunction + def jit_func_2(self, x, g): + B, T, C = x.size() + ...
RWKV-v4neo.src.model/RWKV.configure_optimizers
Modified
BlinkDL~RWKV-LM
673d241cdaaf54cb927f49e2a2ca4542b3d98fab
Merge pull request #178 from fluxlinkage/main
<19>:<add> lr_2x.add(n) <del> lr_3x.add(n) <21>:<add> lr_1x.add(n) <del> lr_2x.add(n)
# module: RWKV-v4neo.src.model class RWKV(pl.LightningModule): def configure_optimizers(self): <0> args = self.args <1> <2> lr_decay = set() <3> lr_1x = set() <4> lr_2x = set() <5> lr_3x = set() <6> for n, p in self.named_param...
===========below chunk 0=========== # module: RWKV-v4neo.src.model class RWKV(pl.LightningModule): def configure_optimizers(self): # offset: 1 param_dict = {n: p for n, p in self.named_parameters()} if args.layerwise_lr > 0: if args.my_pile_stage ...
RWKV-v4neo.src.model/RWKV.generate_init_weight
Modified
BlinkDL~RWKV-LM
673d241cdaaf54cb927f49e2a2ca4542b3d98fab
Merge pull request #178 from fluxlinkage/main
<19>:<add> m[n] = (p * 0.0) + (layer_scale ** 0.7) <del> m[n] = (p * 0.0) + (layer_scale ** 0.5)
# module: RWKV-v4neo.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): <0> print( <1> f""" <2> ############################################################################ <3> # <4> # Init model weight (slow for large models)... <5> # <6> #...
===========below chunk 0=========== # module: RWKV-v4neo.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): # offset: 1 if n == "head.weight": scale = 0.5 if "head_k." in n: ...
RWKV-v4neo.src.model/WKV_5.forward
Modified
BlinkDL~RWKV-LM
653ae70a66f0a9905e232f23ff7936dbbf3b26f7
misc
<1>:<del> assert HEAD_SIZE == C // H <7>:<add> assert HEAD_SIZE == C // H <11>:<add> assert r.is_contiguous() <del> r = r.contiguous() <12>:<add> assert k.is_contiguous() <del> k = k.contiguous() <13>:<add> assert v.is_conti...
# module: RWKV-v4neo.src.model class WKV_5(torch.autograd.Function): @staticmethod def forward(ctx, B, T, C, H, r, k, v, w, u): <0> with torch.no_grad(): <1> assert HEAD_SIZE == C // H <2> assert r.dtype == torch.bfloat16 <3> ...
===========unchanged ref 0=========== at: RWKV-v4neo.src.model HEAD_SIZE = 64 wkv5_cuda = load(name="wkv5", sources=["cuda/wkv5_op.cpp", f"cuda/wkv5_cuda.cu"], verbose=True, extra_cuda_cflags=["-res-usage", "--use_fast_math", "-O3", "-Xptxas -O3", "--extra-device-vectori...
RWKV-v4neo.src.model/WKV_5.backward
Modified
BlinkDL~RWKV-LM
653ae70a66f0a9905e232f23ff7936dbbf3b26f7
misc
<1>:<add> assert gy.dtype == torch.bfloat16 <5>:<add> assert gy.is_contiguous() <del> gy = gy.contiguous() <6>:<del> assert gy.dtype == torch.bfloat16 <8>:<add> gr = torch.empty((B, T, C), device=gy.device, requires_grad=False, dtype=torch.bfloat16, m...
# module: RWKV-v4neo.src.model class WKV_5(torch.autograd.Function): @staticmethod def backward(ctx, gy): <0> with torch.no_grad(): <1> B = ctx.B <2> T = ctx.T <3> C = ctx.C <4> H = ctx.H <5> gy = ...
===========unchanged ref 0=========== at: RWKV-v4neo.src.model wkv5_cuda = load(name="wkv5", sources=["cuda/wkv5_op.cpp", f"cuda/wkv5_cuda.cu"], verbose=True, extra_cuda_cflags=["-res-usage", "--use_fast_math", "-O3", "-Xptxas -O3", "--extra-device-vectorization", f"-D_N_={HEAD_SIZE}...
RWKV-v4neo.src.model/RWKV_TimeMix_RWKV5.__init__
Modified
BlinkDL~RWKV-LM
653ae70a66f0a9905e232f23ff7936dbbf3b26f7
misc
<5>:<add> assert HEAD_SIZE == self.head_size # change HEAD_SIZE to match args.head_size_a
# module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5(MyModule): def __init__(self, args, layer_id): <0> super().__init__() <1> self.args = args <2> ...
===========below chunk 0=========== # module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5(MyModule): def __init__(self, args, layer_id): # offset: 1 self.time_decay = n...
RWKV-v4neo.src.model/RWKV_TimeMix_RWKV5.jit_func
Modified
BlinkDL~RWKV-LM
ad848131362c68ac651b16c0bea25a7ba3f6a6ea
RWKV5 - extra silu for better performance (breaking change)
<10>:<add> v = F.silu(self.value(xv)) <del> v = self.value(xv)
# module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5(MyModule): @MyFunction def jit_func(self, x): <0> B, T, C = x.size() <1> <2> xx = self.time...
===========unchanged ref 0=========== at: RWKV-v4neo.src.model MyFunction = torch.jit.script_method MyFunction = __nop at: RWKV-v4neo.src.model.RWKV_TimeMix_RWKV5.__init__ self.time_mix_k = nn.Parameter(torch.pow(ddd, ratio_1_to_almost0)) self.time_mix_v = nn.Parameter(...
RWKV-v4neo.src.model/RUN_CUDA
Modified
BlinkDL~RWKV-LM
e7a6e5a5362e82eb3a75998ce2f986cbc4902bcb
fix
<0>:<add> return WKV.apply(B, T, C, w, u, k, v) <del> return WKV_5.apply(B, T, C, H, r, k, v, w, u)
# module: RWKV-v4neo.src.model + def RUN_CUDA(B, T, C, w, u, k, v): - def RUN_CUDA(B, T, C, H, r, k, v, w, u): <0> return WKV_5.apply(B, T, C, H, r, k, v, w, u) <1>
===========changed ref 0=========== # module: RWKV-v4neo.src.model ######################################################################################################## # CUDA RWKV5 Kernel ######################################################################################################## ...
RWKV-v4neo.src.model/RWKV_TimeMix_RWKV5.forward
Modified
BlinkDL~RWKV-LM
e7a6e5a5362e82eb3a75998ce2f986cbc4902bcb
fix
<5>:<add> x = RUN_CUDA_RWKV5(B, T, C, H, r, k, v, w=self.time_decay, u=self.time_faaaa) <del> x = RUN_CUDA(B, T, C, H, r, k, v, w=self.time_decay, u=self.time_faaaa)
# module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5(MyModule): def forward(self, x): <0> B, T, C = x.size() <1> H = self.n_head <2> <3> r, k, v...
===========unchanged ref 0=========== at: RWKV-v4neo.src.model RUN_CUDA_RWKV5(B, T, C, H, r, k, v, w, u) at: RWKV-v4neo.src.model.RWKV_TimeMix_RWKV5 jit_func(self, x) jit_func(x) at: RWKV-v4neo.src.model.RWKV_TimeMix_RWKV5.__init__ self.n_head = args.dim_att // self...
RWKV-v4neo.src.model/WKV_5.backward
Modified
BlinkDL~RWKV-LM
3db37a72356b736966ddd377268f02b80963af3f
Merge pull request #186 from PicoCreator/patch-1
<11>:<add> gw = torch.empty((B, C), device=gy.device, requires_grad=False, dtype=torch.bfloat16, memory_format=torch.contiguous_format) # .uniform_(-1, 1) <del> gw = torch.empty((B, T, C), device=gy.device, requires_grad=False, dtype=torch.bfloat16, memory_format=torch.contiguous_fo...
# module: RWKV-v4neo.src.model class WKV_5(torch.autograd.Function): @staticmethod def backward(ctx, gy): <0> with torch.no_grad(): <1> assert gy.dtype == torch.bfloat16 <2> B = ctx.B <3> T = c...
===========below chunk 0=========== # module: RWKV-v4neo.src.model class WKV_5(torch.autograd.Function): @staticmethod def backward(ctx, gy): # offset: 1 ===========unchanged ref 0=========== at: RWKV-v4neo.src.model wkv5_cuda = load(name="wkv5"...
RWKV-v4neo.src.model/RWKV_TimeMix_RWKV5.jit_func
Modified
BlinkDL~RWKV-LM
3db37a72356b736966ddd377268f02b80963af3f
Merge pull request #186 from PicoCreator/patch-1
<10>:<add> v = self.value(xv) <del> v = F.silu(self.value(xv))
# module: RWKV-v4neo.src.model ######################################################################################################## class RWKV_TimeMix_RWKV5(MyModule): @MyFunction def jit_func(self, x): <0> B, T, C = x.size() <1> <2> xx = self.time...
===========unchanged ref 0=========== at: RWKV-v4neo.src.model MyFunction = torch.jit.script_method MyFunction = __nop at: RWKV-v4neo.src.model.RWKV_TimeMix_RWKV5.__init__ self.time_mix_k = nn.Parameter(torch.pow(ddd, ratio_1_to_almost0)) self.time_mix_v = nn.Parameter(...
RWKV-v4neo.src.trainer/train_callback.on_train_batch_start
Modified
BlinkDL~RWKV-LM
06ef9a2199df8e47f356ed8b5195b4fc8de41b41
bugfix & new cuda
<9>:<del> if trainer.global_step < w_step: <10>:<del> lr = lr * (0.2 + 0.8 * trainer.global_step / w_step) <21>:<del> <22>:<del> if trainer.global_step < w_step: <23>:<del> lr = lr * (0.2 + 0.8 * trainer.global_step / w_step)
# module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_start(self, trainer, pl_module, batch, batch_idx): <0> args = self.args <1> # if args.cuda_cleanup > 0: <2> # torch.cuda.empty_cache() <3> real_step = trainer.global_s...
===========below chunk 0=========== # module: RWKV-v4neo.src.trainer class train_callback(pl.Callback): def on_train_batch_start(self, trainer, pl_module, batch, batch_idx): # offset: 1 lr = args.lr_init * (0.2 + 0.8 * trainer.global_step / w_step) else: ...
RWKV-v5.src.model/Block.__init__
Modified
BlinkDL~RWKV-LM
8fea4ebeabc61c03d79763786a7766db65ce45e7
v6 training
<16>:<add> if 'x060' in os.environ["RWKV_MY_TESTING"]: <add> self.att = RWKV_Tmix_x060(args, layer_id) <add> else: <add> self.att = RWKV_TimeMix_RWKV5(args, layer_id) <del> self.att = RWKV_TimeMix_RWKV5(args, layer_id) <21>:<add> ...
# module: RWKV-v5.src.model ######################################################################################################## # The RWKV Model with our blocks ######################################################################################################## class...
===========below chunk 0=========== # module: RWKV-v5.src.model ######################################################################################################## # The RWKV Model with our blocks ######################################################################################################...
RWKV-v5.src.model/RWKV.configure_optimizers
Modified
BlinkDL~RWKV-LM
8fea4ebeabc61c03d79763786a7766db65ce45e7
v6 training
<7>:<add> if (("_w1" in n) or ("_w2" in n)) and (args.layerwise_lr > 0): <add> lr_1x.add(n) <add> elif (("time_mix" in n) or ("time_maa" in n)) and (args.layerwise_lr > 0): <del> if ("time_mix" in n) and (args.layerwise_lr > 0): <12>:<add> ...
# module: RWKV-v5.src.model class RWKV(pl.LightningModule): def configure_optimizers(self): <0> args = self.args <1> <2> lr_decay = set() <3> lr_1x = set() <4> lr_2x = set() <5> lr_3x = set() <6> for n, p in self.named_paramete...
===========below chunk 0=========== # module: RWKV-v5.src.model class RWKV(pl.LightningModule): def configure_optimizers(self): # offset: 1 if args.layerwise_lr > 0: if args.my_pile_stage == 2: optim_groups = [ {"pa...
RWKV-v5.src.model/RWKV_Tmix_x060.__init__
Modified
BlinkDL~RWKV-LM
62572c917d8b4d27456085cb43e43883fa9a9e52
better
# module: RWKV-v5.src.model class RWKV_Tmix_x060(MyModule): def __init__(self, args, layer_id): <0> super().__init__() <1> self.args = args <2> self.layer_id = layer_id <3> <4> self.head_size = args.head_size_a <5> self.n_head = args.dim_att // ...
===========below chunk 0=========== # module: RWKV-v5.src.model class RWKV_Tmix_x060(MyModule): def __init__(self, args, layer_id): # offset: 1 TIME_MIX_EXTRA_DIM = 32 # generate TIME_MIX for w,k,v,r,g self.time_maa_w1 = nn.Parameter(torch.empty(args.n_embd, TIME...
RWKV-v5.src.model/RWKV_Tmix_x060.__init__
Modified
BlinkDL~RWKV-LM
cf854f356103a7848fc1f69352bebb5ec153de47
misc
# module: RWKV-v5.src.model class RWKV_Tmix_x060(MyModule): def __init__(self, args, layer_id): <0> super().__init__() <1> self.args = args <2> self.layer_id = layer_id <3> <4> self.head_size = args.head_size_a <5> self.n_head = args.dim_att // ...
===========below chunk 0=========== # module: RWKV-v5.src.model class RWKV_Tmix_x060(MyModule): def __init__(self, args, layer_id): # offset: 1 TIME_MIX_EXTRA_DIM = 32 # generate TIME_MIX for w,k,v,r,g self.time_maa_w1 = nn.Parameter(torch.zeros(args.n_embd, TIME...
RWKV-v5.src.model/RWKV.__init__
Modified
BlinkDL~RWKV-LM
cf854f356103a7848fc1f69352bebb5ec153de47
misc
<5>:<add> args.dim_ffn = int((args.n_embd * 3.5) // 32 * 32) # default = 3.5x emb size <del> args.dim_ffn = args.n_embd * 4
# module: RWKV-v5.src.model class RWKV(pl.LightningModule): def __init__(self, args): <0> super().__init__() <1> self.args = args <2> if not hasattr(args, 'dim_att'): <3> args.dim_att = args.n_embd <4> if not hasattr(args, 'dim_ffn'): <5> ...
===========unchanged ref 0=========== at: torch._C._VariableFunctions ones(size: _size, *, names: Optional[Sequence[Union[str, ellipsis, None]]], dtype: Optional[_dtype]=None, layout: Optional[_layout]=None, device: Optional[Union[_device, str, None]]=None, pin_memory: Optional[_bool]=False, requires_grad: ...
RWKV-v5.src.model/Block.__init__
Modified
BlinkDL~RWKV-LM
461c87c7dce7e149cf61331bd7a4aba671ab924e
better guide
<18>:<add> elif 'x052' in os.environ["RWKV_MY_TESTING"]: <del> else: <19>:<add> self.att = RWKV_Tmix_x052(args, layer_id) <del> self.att = RWKV_TimeMix_RWKV5(args, layer_id) <26>:<add> elif 'x052' in os.environ["RWKV_MY_TESTING"]: <del> ...
# module: RWKV-v5.src.model ######################################################################################################## # The RWKV Model with our blocks ######################################################################################################## class...
===========below chunk 0=========== # module: RWKV-v5.src.model ######################################################################################################## # The RWKV Model with our blocks ######################################################################################################...
RWKV-v5.src.model/Block.__init__
Modified
BlinkDL~RWKV-LM
e7c27f00dde647b72636ae72f27a167a53987217
Merge branch 'main' of https://github.com/BlinkDL/RWKV-LM
<20>:<add> elif 'mamba' in os.environ["RWKV_MY_TESTING"]: <add> self.att = Mamba(d_model=args.n_embd, d_state=16, d_conv=4, expand=2.125) # match rwkv6 #params <23>:<del> else: <24>:<add> elif 'x060' in os.environ["RWKV_MY_TESTING"]: <del> if 'x060' in o...
# module: RWKV-v5.src.model ######################################################################################################## # The RWKV Model with our blocks ######################################################################################################## class...
===========below chunk 0=========== # module: RWKV-v5.src.model ######################################################################################################## # The RWKV Model with our blocks ######################################################################################################...
RWKV-v5.src.model/RWKV.generate_init_weight
Modified
BlinkDL~RWKV-LM
e7c27f00dde647b72636ae72f27a167a53987217
Merge branch 'main' of https://github.com/BlinkDL/RWKV-LM
<10>:<add> n_params = 0 <13>:<add> <add> s0 = str(shape[0]) if len(shape) > 0 else "" <add> s1 = str(shape[1]) if len(shape) > 1 else "" <add> s2 = str(shape[2]) if len(shape) > 2 else "" <add> print(f"{s0.ljust(5)} {s1.ljust(5)} {s2.ljust(5)}...
# module: RWKV-v5.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): <0> print( <1> f""" <2> ############################################################################ <3> # <4> # Init model weight (slow for large models)... <5> # <6> ####...
===========below chunk 0=========== # module: RWKV-v5.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): # offset: 1 if self.args.accelerator.upper() == "GPU": m[n] = torch.empty((shape[0], shape[1]), device="cuda") ...
RWKV-v5.src.model/RWKV.generate_init_weight
Modified
BlinkDL~RWKV-LM
4e2e255b9ad9ec4dd075b20d70e177c3aeb135f2
better
# module: RWKV-v5.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): <0> print( <1> f""" <2> ############################################################################ <3> # <4> # Init model weight (slow for large models)... <5> # <6> ####...
===========below chunk 0=========== # module: RWKV-v5.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): # offset: 1 scale = 0.5 nn.init.orthogonal_(m[n], gain=gain * scale) print(f" [scale {sc...
RWKV-v5.src.model/RWKV.generate_init_weight
Modified
BlinkDL~RWKV-LM
402dab6bd3bb22acd4b149ff04f1a8ab149317b1
fix init
<37>:<add> if shape[1] > shape[0]: # !!! only for pytorch where linear layer weight is transposed !!! <del> if shape[0] > shape[1]: <38>:<add> gain = math.sqrt(shape[1] / shape[0]) <del> gain = math.sqrt(sh...
# module: RWKV-v5.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): <0> print( <1> f""" <2> ############################################################################ <3> # <4> # Init model weight (slow for large models)... <5> # <6> ####...
===========below chunk 0=========== # module: RWKV-v5.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): # offset: 1 scale = 0.5 nn.init.orthogonal_(m[n], gain=gain * scale) print(f" [scale {sc...
RWKV-v5.src.model/RWKV_Tmix_x060.__init__
Modified
BlinkDL~RWKV-LM
2142cb78e9bca400991008400b257176788badb4
MODEL_TYPE "x060a-f4" (sometimes better)
# module: RWKV-v5.src.model class RWKV_Tmix_x060(MyModule): def __init__(self, args, layer_id): <0> super().__init__() <1> self.args = args <2> self.layer_id = layer_id <3> <4> self.head_size = args.head_size_a <5> self.n_head = args.dim_att // ...
===========below chunk 0=========== # module: RWKV-v5.src.model class RWKV_Tmix_x060(MyModule): def __init__(self, args, layer_id): # offset: 1 TIME_MIX_EXTRA_DIM = 32 # generate TIME_MIX for w,k,v,r,g self.time_maa_w1 = nn.Parameter(torch.zeros(args.n_embd, TIME...
RWKV-v5.src.model/Block.__init__
Modified
BlinkDL~RWKV-LM
2142cb78e9bca400991008400b257176788badb4
MODEL_TYPE "x060a-f4" (sometimes better)
<16>:<add> if 'x060a' in os.environ["RWKV_MY_TESTING"]: <del> if 'x060' in os.environ["RWKV_MY_TESTING"]: <17>:<add> self.att = RWKV_Tmix_x060a(args, layer_id) <add> elif 'x060' in os.environ["RWKV_MY_TESTING"]:
# module: RWKV-v5.src.model ######################################################################################################## # The RWKV Model with our blocks ######################################################################################################## class...
===========below chunk 0=========== # module: RWKV-v5.src.model ######################################################################################################## # The RWKV Model with our blocks ######################################################################################################...
RWKV-v5.src.model/RWKV.__init__
Modified
BlinkDL~RWKV-LM
2142cb78e9bca400991008400b257176788badb4
MODEL_TYPE "x060a-f4" (sometimes better)
<5>:<add> if '-f4' in os.environ["RWKV_MY_TESTING"]: <add> args.dim_ffn = int((args.n_embd * 4) // 32 * 32) <add> else: <add> args.dim_ffn = int((args.n_embd * 3.5) // 32 * 32) # default = 3.5x emb size <del> args.dim_f...
# module: RWKV-v5.src.model class RWKV(pl.LightningModule): def __init__(self, args): <0> super().__init__() <1> self.args = args <2> if not hasattr(args, 'dim_att'): <3> args.dim_att = args.n_embd <4> if not hasattr(args, 'dim_ffn'): <5> ...
===========unchanged ref 0=========== at: torch._C._VariableFunctions zeros(*size: _int, out: Optional[Tensor]=None, dtype: Optional[_dtype]=None, layout: Optional[_layout]=None, device: Optional[Union[_device, str, None]]=None, pin_memory: Optional[_bool]=False, requires_grad: Optional[_bool]=False) -> Ten...
RWKV-v5.src.model/RWKV.generate_init_weight
Modified
BlinkDL~RWKV-LM
2142cb78e9bca400991008400b257176788badb4
MODEL_TYPE "x060a-f4" (sometimes better)
<22>:<add> if "ln_" in n or ".ln" in n or "time_" in n or "_mask" in n or "pos_emb" in n or '.mask.' in n or n.endswith('_w') or n.endswith('_w1') or n.endswith('_w2') or n.endswith('_bias'): <del> if "ln_" in n or ".ln" in n or "time_" in n or "_mask" in n or "pos_emb" in n or '.mask.' in ...
# module: RWKV-v5.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): <0> print( <1> f""" <2> ############################################################################ <3> # <4> # Init model weight (slow for large models)... <5> # <6> ####...
===========below chunk 0=========== # module: RWKV-v5.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): # offset: 1 gain = math.sqrt(shape[1] / shape[0]) nn.init.orthogonal_(m[n], gain=gain * scale) ...
RWKV-v5.src.model/WKV_6.forward
Modified
BlinkDL~RWKV-LM
ffb089b9b21063bb4c247f900b71a917556ad522
faster v6 cuda
<16>:<del> ew = (-torch.exp(w.float())).contiguous() <17>:<add> ctx.save_for_backward(r, k, v, w, u) <del> ctx.save_for_backward(r, k, v, ew, u) <19>:<add> wkv6_cuda.forward(B, T, C, H, r, k, v, w, u, y) <del> wkv6_cuda.forward(B,...
# module: RWKV-v5.src.model class WKV_6(torch.autograd.Function): @staticmethod def forward(ctx, B, T, C, H, r, k, v, w, u): <0> with torch.no_grad(): <1> assert r.dtype == torch.bfloat16 <2> assert k.dtype == t...
===========unchanged ref 0=========== at: RWKV-v5.src.model HEAD_SIZE = int(os.environ["RWKV_HEAD_SIZE_A"]) wkv6_cuda = load(name="wkv6", sources=["cuda/wkv6_op.cpp", f"cuda/wkv6_cuda.cu"], verbose=True, extra_cuda_cflags=["-res-usage", "--use_fast_math", "-O3", "-Xp...
RWKV-v5.src.model/WKV_6.backward
Modified
BlinkDL~RWKV-LM
ffb089b9b21063bb4c247f900b71a917556ad522
faster v6 cuda
<7>:<add> r, k, v, w, u = ctx.saved_tensors <del> r, k, v, ew, u = ctx.saved_tensors <13>:<add> wkv6_cuda.backward(B, T, C, H, r, k, v, w, u, gy, gr, gk, gv, gw, gu) <del> wkv6_cuda.backward(B, T, C, H, r, k, v, ew, u, gy, gr, gk, gv, gw, gu)
# module: RWKV-v5.src.model class WKV_6(torch.autograd.Function): @staticmethod def backward(ctx, gy): <0> with torch.no_grad(): <1> assert gy.dtype == torch.bfloat16 <2> B = ctx.B <3> T = ctx....
===========unchanged ref 0=========== at: RWKV-v5.src.model wkv6_cuda = load(name="wkv6", sources=["cuda/wkv6_op.cpp", f"cuda/wkv6_cuda.cu"], verbose=True, extra_cuda_cflags=["-res-usage", "--use_fast_math", "-O3", "-Xptxas -O3", "--extra-device-vectorization", f"-D_N_={HEAD_SIZE...
RWKV-v5.src.model/RWKV.generate_init_weight
Modified
BlinkDL~RWKV-LM
43045b702a509eca80237d2516887a0f79dc7984
fix
<20>:<del> gain = 1.0 <29>:<add> elif n == "emb.weight": <add> m[n] = p <add> scale = -1e-4 <add> nn.init.uniform_(m[n], a=scale, b=-scale) <add> print(f" [scale {scale}]") <add> elif n == "head....
# module: RWKV-v5.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): <0> print( <1> f""" <2> ############################################################################ <3> # <4> # Init model weight (slow for large models)... <5> # <6> ####...
===========below chunk 0=========== # module: RWKV-v5.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): # offset: 1 elif n == "head.weight": if shape[1] > shape[0]: # !!! only for pytorch where linear layer weight is transpo...
RWKV-v5.src.model/Block.__init__
Modified
BlinkDL~RWKV-LM
033ce840de872dd67c42ed9f9bba08fa2d683eb7
v6.0b & prepare for state-tuning
<18>:<add> elif 'x060b' in os.environ["RWKV_MY_TESTING"]: <add> self.att = RWKV_Tmix_x060b(args, layer_id)
# module: RWKV-v5.src.model ######################################################################################################## # The RWKV Model with our blocks ######################################################################################################## class...
===========below chunk 0=========== # module: RWKV-v5.src.model ######################################################################################################## # The RWKV Model with our blocks ######################################################################################################...
RWKV-v5.src.model/Block.__init__
Modified
BlinkDL~RWKV-LM
1a44eede5f6bd9610944d7c4787a8f2f867a12d6
state-tuning (not working yet)
<21>:<add> if os.environ["RWKV_TRAIN_TYPE"] == 'states': <add> self.att = RWKV_Tmix_x060_state(args, layer_id) <add> else: <add> self.att = RWKV_Tmix_x060(args, layer_id) <del> self.att = RWKV_Tmix_x060(args, lay...
# module: RWKV-v5.src.model ######################################################################################################## # The RWKV Model with our blocks ######################################################################################################## class...
===========below chunk 0=========== # module: RWKV-v5.src.model ######################################################################################################## # The RWKV Model with our blocks ######################################################################################################...
RWKV-v5.src.model/RWKV.configure_optimizers
Modified
BlinkDL~RWKV-LM
1a44eede5f6bd9610944d7c4787a8f2f867a12d6
state-tuning (not working yet)
<7>:<add> if not p.requires_grad: <add> continue
# module: RWKV-v5.src.model class RWKV(pl.LightningModule): def configure_optimizers(self): <0> args = self.args <1> <2> lr_decay = set() <3> lr_1x = set() <4> lr_2x = set() <5> lr_3x = set() <6> for n, p in self.named_paramete...
===========below chunk 0=========== # module: RWKV-v5.src.model class RWKV(pl.LightningModule): def configure_optimizers(self): # offset: 1 # print('decay', lr_decay) # print('1x', lr_1x) # print('2x', lr_2x) # print('3x', lr_3x) param_dict...
RWKV-v5.src.dataset/MyDataset.__init__
Modified
BlinkDL~RWKV-LM
1a44eede5f6bd9610944d7c4787a8f2f867a12d6
state-tuning (not working yet)
# module: RWKV-v5.src.dataset class MyDataset(Dataset): def __init__(self, args): <0> self.args = args <1> <2> if args.data_type == "binidx": <3> self.vocab_size = args.vocab_size <4> rank_zero_info(f"Current vocab size = {self.vocab_size} (make s...
===========below chunk 0=========== # module: RWKV-v5.src.dataset class MyDataset(Dataset): def __init__(self, args): # offset: 1 else: self.data_pile = None self.data_pile_size = 0 if args.my_pile_stage > 0: ...
RWKV-v5.src.model/RWKV.configure_optimizers
Modified
BlinkDL~RWKV-LM
5d856c2ce27709d1ef715608f4701f9605956376
still testing state-tuning...
<7>:<add> <add> # if not p.requires_grad: <del> if not p.requires_grad: <8>:<add> # continue <del> continue <9>:<add> if args.train_type == 'states': <add> if 'time_state' not in n: <add> ...
# module: RWKV-v5.src.model class RWKV(pl.LightningModule): def configure_optimizers(self): <0> args = self.args <1> <2> lr_decay = set() <3> lr_1x = set() <4> lr_2x = set() <5> lr_3x = set() <6> for n, p in self.named_paramete...
===========below chunk 0=========== # module: RWKV-v5.src.model class RWKV(pl.LightningModule): def configure_optimizers(self): # offset: 1 lr_3x = sorted(list(lr_3x)) if self.trainer.is_global_zero: print('decay', lr_decay, '\n') print('1...
RWKV-v5.src.model/RWKV.configure_optimizers
Modified
BlinkDL~RWKV-LM
64b7fe4c66fcf7da37019630268075b0558f6dc5
better state training
<11>:<add> if 'time_sta' not in n: <del> if 'time_state' not in n: <16>:<add> elif (("time_sta" in n) and (args.weight_decay > 0)): <add> lr_decay.add(n)
# module: RWKV-v5.src.model class RWKV(pl.LightningModule): def configure_optimizers(self): <0> args = self.args <1> <2> lr_decay = set() <3> lr_1x = set() <4> lr_2x = set() <5> lr_3x = set() <6> for n, p in self.named_paramete...
===========below chunk 0=========== # module: RWKV-v5.src.model class RWKV(pl.LightningModule): def configure_optimizers(self): # offset: 1 lr_1x = sorted(list(lr_1x)) lr_2x = sorted(list(lr_2x)) lr_3x = sorted(list(lr_3x)) if self.trainer.is_glob...
RWKV-v5.src.trainer/my_save
Modified
BlinkDL~RWKV-LM
64b7fe4c66fcf7da37019630268075b0558f6dc5
better state training
<15>:<add> if args.train_type == 'states': <add> ddd = {} <add> for k, v in dd.items(): <add> if 'time_sta' in k: <add> ddd[k] = v.clone() <add> torch.save(ddd, ff) <add> els...
# module: RWKV-v5.src.trainer def my_save(args, trainer, dd, ff): <0> if '14b-run1' in ff: <1> fn = ff.split('/')[-1] <2> fff = '/dev/shm/' + fn <3> torch.save(dd, fff) <4> subprocess.Popen(f" aws s3 mv {fff} s3://rwkv-14b-4k/{fn} --quiet", shell=True) <5> ...
===========unchanged ref 0=========== at: subprocess Popen() at: torch.serialization save(obj: object, f: FILE_LIKE, pickle_module: Any=pickle, pickle_protocol: int=DEFAULT_PROTOCOL, _use_new_zipfile_serialization: bool=True, _disable_byteorder_record: bool=False) -> None ========...
RWKV-v5.src.model/RWKV_Tmix_x060c.jit_func
Modified
BlinkDL~RWKV-LM
bf86e0cec3bc876aa93305200d271fc1f0c43e92
.
<19>:<add> # k = k * (1-(-w.exp()).exp()) # for fp32 <del> k = k * (1-(-w.exp()).exp()) <20>:<add> k = k * (1-(-w.float().exp()).exp()).to(dtype=torch.bfloat16) # for bf16
# module: RWKV-v5.src.model ######################################################################################################## class RWKV_Tmix_x060c(MyModule): @MyFunction def jit_func(self, x): <0> B, T, C = x.size() <1> <2> xx = self...
===========unchanged ref 0=========== at: RWKV-v5.src.model MyFunction = torch.jit.script_method MyFunction = __nop at: RWKV-v5.src.model.RWKV_Tmix_x060c.__init__ self.time_maa_x = nn.Parameter(1.0 - torch.pow(ddd, ratio_1_to_almost0)) self.time_maa_r = nn.Parameter(1.0...
RWKV-v5.src.model/WKV_6.forward
Modified
BlinkDL~RWKV-LM
86affd71c53425d1abc5398f940b09fd8c2a3a99
fully compatible with torch jit
<1>:<add> B, T, C = r.size() <add> H = C // HEAD_SIZE <add> assert C % HEAD_SIZE == 0 <6>:<del> assert HEAD_SIZE == C // H <18>:<add> torch.ops.wkv6.forward(B, T, C, H, r, k, v, w, u, y) <del> ...
# module: RWKV-v5.src.model class WKV_6(torch.autograd.Function): @staticmethod + def forward(ctx, r, k, v, w, u): - def forward(ctx, B, T, C, H, r, k, v, w, u): <0> with torch.no_grad(): <1> ...
===========unchanged ref 0=========== at: RWKV-v5.src.model HEAD_SIZE = int(os.environ["RWKV_HEAD_SIZE_A"]) at: torch._C bfloat16: dtype = ... contiguous_format: memory_format = ... at: torch._C._VariableFunctions empty(size: _size, *, names: Optional[Sequence[...
RWKV-v5.src.model/WKV_6.backward
Modified
BlinkDL~RWKV-LM
86affd71c53425d1abc5398f940b09fd8c2a3a99
fully compatible with torch jit
<13>:<add> torch.ops.wkv6.backward(B, T, C, H, r, k, v, w, u, gy, gr, gk, gv, gw, gu) <del> wkv6_cuda.backward(B, T, C, H, r, k, v, w, u, gy, gr, gk, gv, gw, gu) <15>:<add> return (gr, gk, gv, gw, gu) <del> return (None, None, Non...
# module: RWKV-v5.src.model class WKV_6(torch.autograd.Function): @staticmethod def backward(ctx, gy): <0> with torch.no_grad(): <1> assert gy.dtype == torch.bfloat16 <2> B = ctx.B <...
===========unchanged ref 0=========== at: RWKV-v5.src.model.WKV_6.forward y = torch.empty((B, T, C), device=r.device, dtype=torch.bfloat16, memory_format=torch.contiguous_format)#.uniform_(-100, 100) at: torch._C bfloat16: dtype = ... contiguous_format: memory_format = ... ...
RWKV-v5.src.model/RUN_CUDA_RWKV6
Modified
BlinkDL~RWKV-LM
86affd71c53425d1abc5398f940b09fd8c2a3a99
fully compatible with torch jit
<0>:<add> return WKV_6.apply(r, k, v, w, u) <del> return WKV_6.apply(B, T, C, H, r, k, v, w, u)
# module: RWKV-v5.src.model + def RUN_CUDA_RWKV6(r, k, v, w, u): - def RUN_CUDA_RWKV6(B, T, C, H, r, k, v, w, u): <0> return WKV_6.apply(B, T, C, H, r, k, v, w, u) <1>
===========unchanged ref 0=========== at: RWKV-v5.src.model.WKV_6.backward gr = torch.empty((B, T, C), device=gy.device, requires_grad=False, dtype=torch.bfloat16, memory_format=torch.contiguous_format)#.uniform_(-100, 100) gk = torch.empty((B, T, C), device=gy.device, requires_grad=False, dtyp...
RWKV-v5.src.model/RWKV_Tmix_x060.forward
Modified
BlinkDL~RWKV-LM
86affd71c53425d1abc5398f940b09fd8c2a3a99
fully compatible with torch jit
<1>:<del> H = self.n_head <3>:<del> r, k, v, g, w = self.jit_func(x) <4>:<del> x = RUN_CUDA_RWKV6(B, T, C, H, r, k, v, w, u=self.time_faaaa) <5>:<add> xx = self.time_shift(x) - x <6>:<add> xxx = x + xx * self.time_maa_x <add> xxx = torch.tanh(xxx @ self.time_maa...
# module: RWKV-v5.src.model class RWKV_Tmix_x060(MyModule): + @MyFunction def forward(self, x): <0> B, T, C = x.size() <1> H = self.n_head <2> <3> r, k, v, g, w = self.jit_func(x) <4> x = RUN_CUDA_RWKV6(B, T, C, H, r, k, v, w, u=self.time_faaaa) ...
===========unchanged ref 0=========== at: RWKV-v5.src.model MyModule = nn.Module MyModule = torch.jit.ScriptModule at: torch.jit._script.ScriptModule __jit_unused_properties__ = [ "code", "code_with_constants", "graph", ...
RWKV-v5.src.model/RWKV_Tmix_x060a.forward
Modified
BlinkDL~RWKV-LM
86affd71c53425d1abc5398f940b09fd8c2a3a99
fully compatible with torch jit
<1>:<del> H = self.n_head <3>:<del> r, k, v, g, w = self.jit_func(x) <4>:<del> x = RUN_CUDA_RWKV6(B, T, C, H, r, k, v, w, u=self.time_faaaa) <5>:<add> xx = self.time_shift(x) - x <6>:<add> xxx = x + xx * self.time_maa_x <add> xxx = torch.tanh(xxx @ self.time_maa...
# module: RWKV-v5.src.model ######################################################################################################## class RWKV_Tmix_x060a(MyModule): + @MyFunction def forward(self, x): <0> B, T, C = x.size() <1> H = self.n_head <2> <3> ...
===========unchanged ref 0=========== at: RWKV-v5.src.model.RWKV_Tmix_x060b.__init__ ratio_0_to_1 = layer_id / (args.n_layer - 1) # 0 to 1 ratio_1_to_almost0 = 1.0 - (layer_id / args.n_layer) # 1 to ~0 at: torch._C._VariableFunctions ones(size: _size, *, names: Optional[Seque...
RWKV-v5.src.model/RWKV_Tmix_x060b.forward
Modified
BlinkDL~RWKV-LM
86affd71c53425d1abc5398f940b09fd8c2a3a99
fully compatible with torch jit
<1>:<del> H = self.n_head <3>:<del> r, k, v, w = self.jit_func(x) <4>:<del> x = RUN_CUDA_RWKV6(B, T, C, H, r, k, v, w, u=self.time_faaaa) <5>:<add> xx = self.time_shift(x) - x <6>:<add> xxx = x + xx * self.time_maa_x <add> xxx = torch.tanh(xxx @ self.time_maa_rk...
# module: RWKV-v5.src.model + ######################################################################################################## class RWKV_Tmix_x060b(MyModule): + @MyFunction def forward(self, x): <0> B, T, C = x.size() <1> H = self.n_head ...
===========unchanged ref 0=========== at: RWKV-v5.src.model.RWKV_Tmix_x060c.__init__ ratio_0_to_1 = layer_id / (args.n_layer - 1) # 0 to 1 at: torch._C._VariableFunctions ones(size: _size, *, names: Optional[Sequence[Union[str, ellipsis, None]]], dtype: Optional[_dtype]=None, layout: Optio...
RWKV-v5.src.model/RWKV_Tmix_x060c.forward
Modified
BlinkDL~RWKV-LM
86affd71c53425d1abc5398f940b09fd8c2a3a99
fully compatible with torch jit
<1>:<del> H = self.n_head <3>:<del> r, k, v, w = self.jit_func(x) <4>:<del> x = RUN_CUDA_RWKV6(B, T, C, H, r, k, v, w, u=self.time_faaaa) <5>:<add> xx = self.time_shift(x) - x <6>:<add> xxx = x + xx * self.time_maa_x <add> xxx = torch.tanh(xxx @ self.time_maa_rk...
# module: RWKV-v5.src.model ######################################################################################################## class RWKV_Tmix_x060c(MyModule): + @MyFunction def forward(self, x): <0> B, T, C = x.size() <1> H = self.n_head ...
===========unchanged ref 0=========== at: torch._C._VariableFunctions ones(size: _size, *, names: Optional[Sequence[Union[str, ellipsis, None]]], dtype: Optional[_dtype]=None, layout: Optional[_layout]=None, device: Optional[Union[_device, str, None]]=None, pin_memory: Optional[_bool]=False, requires_grad: ...
RWKV-v5.src.trainer/train_callback.on_train_batch_start
Modified
BlinkDL~RWKV-LM
97c8aaee96ae7dee4c86535cf0c0e92b97595ab4
Update trainer.py
# module: RWKV-v5.src.trainer class train_callback(pl.Callback): def on_train_batch_start(self, trainer, pl_module, batch, batch_idx): <0> args = self.args <1> # if args.cuda_cleanup > 0: <2> # torch.cuda.empty_cache() <3> real_step = trainer.global_step...
===========below chunk 0=========== # module: RWKV-v5.src.trainer class train_callback(pl.Callback): def on_train_batch_start(self, trainer, pl_module, batch, batch_idx): # offset: 1 lr_final_factor = args.lr_final / args.lr_init lr_mult = (0.5 + lr_fi...
RWKV-v7.rwkv_v7_demo/RWKV_Tmix_x070.__init__
Modified
BlinkDL~RWKV-LM
bd74d483b3531388a43fc2fc0ca7ffe68143da13
rwkv-7 rc3
# module: RWKV-v7.rwkv_v7_demo ######################################################################################################## # RWKV TimeMix ######################################################################################################## class RWKV_Tmix_x070(nn.Mod...
===========below chunk 0=========== # module: RWKV-v7.rwkv_v7_demo ######################################################################################################## # RWKV TimeMix ######################################################################################################## cla...
RWKV-v7.rwkv_v7_demo/RWKV_Tmix_x070.forward
Modified
BlinkDL~RWKV-LM
bd74d483b3531388a43fc2fc0ca7ffe68143da13
rwkv-7 rc3
# module: RWKV-v7.rwkv_v7_demo ######################################################################################################## # RWKV TimeMix ######################################################################################################## class RWKV_Tmix_x070(nn.Mod...
===========below chunk 0=========== # module: RWKV-v7.rwkv_v7_demo ######################################################################################################## # RWKV TimeMix ######################################################################################################## cla...
RWKV-v7.rwkv_v7_demo/RWKV_Tmix_x070.__init__
Modified
BlinkDL~RWKV-LM
c453b42656baa206cf5e9441482c97448c0d221a
rwkv-7 rc4
<24>:<add> ### TOO MANY LORAs HERE. I WILL REMOVE MOST OF THEM IN RWKV-7 FINAL :) ### <add>
# module: RWKV-v7.rwkv_v7_demo ######################################################################################################## # RWKV TimeMix ######################################################################################################## class RWKV_Tmix_x070(nn.Mod...
===========below chunk 0=========== # module: RWKV-v7.rwkv_v7_demo ######################################################################################################## # RWKV TimeMix ######################################################################################################## cla...
RWKV-v7.rwkv_v7_demo/RWKV_Tmix_x070.forward
Modified
BlinkDL~RWKV-LM
c453b42656baa206cf5e9441482c97448c0d221a
rwkv-7 rc4
<20>:<add> if self.layer_id == 0: <add> v0 = v <add> else: <add> v = v + (v0 - v) * torch.sigmoid(self.time_misc_v + (xv @ self.mv_w1) @ self.mv_w2) <add> g = torch.sigmoid(xg @ self.gate_w1) @ self.gate_w2 <del> g = torch.tanh(xg @ self.g...
# module: RWKV-v7.rwkv_v7_demo ######################################################################################################## # RWKV TimeMix ######################################################################################################## class RWKV_Tmix_x070(nn.Mod...
===========below chunk 0=========== # module: RWKV-v7.rwkv_v7_demo ######################################################################################################## # RWKV TimeMix ######################################################################################################## cla...
RWKV-v7.rwkv_v7_demo/Block.__init__
Modified
BlinkDL~RWKV-LM
c453b42656baa206cf5e9441482c97448c0d221a
rwkv-7 rc4
<11>:<add> self.ffn = RWKV_CMix_x070(args, layer_id) <del> self.ffn = RWKV_CMix_x060(args, layer_id)
# module: RWKV-v7.rwkv_v7_demo ######################################################################################################## # RWKV Block ######################################################################################################## class Block(nn.Module): ...
===========unchanged ref 0=========== at: torch.nn.modules.module Module() at: torch.nn.modules.module.Module __init__(self) -> None __init__() -> None at: torch.nn.modules.normalization LayerNorm(normalized_shape: _shape_t, eps: float=1e-5, elementwise_affine: bool...
RWKV-v7.rwkv_v7_demo/Block.forward
Modified
BlinkDL~RWKV-LM
c453b42656baa206cf5e9441482c97448c0d221a
rwkv-7 rc4
<3>:<add> xx, v0 = self.att(self.ln1(x), v0) <del> x = x + self.att(self.ln1(x)) <4>:<add> x = x + xx <6>:<add> # if RESCALE_LAYER > 0: <del> if RESCALE_LAYER > 0: <7>:<add> # if (self.layer_id+1) % RESCALE_LAYER == 0: <del> if (self.lay...
# module: RWKV-v7.rwkv_v7_demo ######################################################################################################## # RWKV Block ######################################################################################################## class Block(nn.Module): ...
===========unchanged ref 0=========== at: RWKV-v7.rwkv_v7_demo RWKV_CMix_x070(args, layer_id) at: RWKV-v7.rwkv_v7_demo.Block.__init__ self.layer_id = layer_id self.ln1 = nn.LayerNorm(args.n_embd) self.ln2 = nn.LayerNorm(args.n_embd) self.att = RWKV_Tmi...
RWKV-v7.rwkv_v7_demo/RWKV.forward
Modified
BlinkDL~RWKV-LM
c453b42656baa206cf5e9441482c97448c0d221a
rwkv-7 rc4
<2>:<add> v0 = torch.empty_like(x) <3>:<add> x, v0 = block(x, v0) <del> x = block(x)
# module: RWKV-v7.rwkv_v7_demo ######################################################################################################## # RWKV Model ######################################################################################################## class RWKV(nn.Module): ...
===========unchanged ref 0=========== at: RWKV-v7.rwkv_v7_demo Block(args, layer_id) at: RWKV-v7.rwkv_v7_demo.RWKV.__init__ self.emb = nn.Embedding(args.vocab_size, args.n_embd) at: torch._C._VariableFunctions empty_like(input: Tensor, *, memory_format: Optional[memory_form...
RWKV-v5.src.model/RWKV_CMix_x060.__init__
Modified
BlinkDL~RWKV-LM
b44816c689f9d37448de1a64cc6a7fa44995d9f2
RWKV-7 (preview) training
<10>:<add> self.time_maa_k = nn.Parameter(1.0 - torch.pow(ddd, ratio_1_to_almost0**3)) <del> self.time_maa_k = nn.Parameter(1.0 - torch.pow(ddd, ratio_1_to_almost0)) <11>:<add> self.time_maa_r = nn.Parameter(1.0 - torch.pow(ddd, ratio_1_to_almost0**3)) <del> sel...
# module: RWKV-v5.src.model class RWKV_CMix_x060(MyModule): def __init__(self, args, layer_id): <0> super().__init__() <1> self.args = args <2> self.layer_id = layer_id <3> self.time_shift = nn.ZeroPad2d((0, 0, 1, -1)) <4> <5> with torch.no_grad...
===========changed ref 0=========== # module: RWKV-v5.src.model + def RUN_CUDA_RWKV7g(q,w,k,v,a,b): + B,T,HC = q.shape + q,w,k,v,a,b = [i.view(B,T,HC//64,64) for i in [q,w,k,v,a,b]] + return WindBackstepping.apply(w,q,k,v,a,b).view(B,T,HC) + ===========changed ref 1===========...
RWKV-v5.src.model/Block.__init__
Modified
BlinkDL~RWKV-LM
b44816c689f9d37448de1a64cc6a7fa44995d9f2
RWKV-7 (preview) training
<16>:<add> if 'x070' in os.environ["RWKV_MY_TESTING"]: <add> self.att = RWKV_Tmix_x070(args, layer_id) <add> elif 'x060a' in os.environ["RWKV_MY_TESTING"]: <del> if 'x060a' in os.environ["RWKV_MY_TESTING"]:
# module: RWKV-v5.src.model ######################################################################################################## # The RWKV Model with our blocks ######################################################################################################## class...
===========below chunk 0=========== # module: RWKV-v5.src.model ######################################################################################################## # The RWKV Model with our blocks ######################################################################################################...
RWKV-v5.src.model/RWKV.forward
Modified
BlinkDL~RWKV-LM
b44816c689f9d37448de1a64cc6a7fa44995d9f2
RWKV-7 (preview) training
<16>:<add> if 'x070' in os.environ["RWKV_MY_TESTING"]: <add> v0 = torch.empty_like(x) <add> for block in self.blocks: <del> for block in self.blocks: <17>:<add> if args.grad_cp == 1: <del> if args.grad_cp == ...
# module: RWKV-v5.src.model class RWKV(pl.LightningModule): def forward(self, idx): <0> args = self.args <1> B, T = idx.size() <2> assert T <= args.ctx_len, "Cannot forward, model ctx_len is exhausted." <3> <4> x = self.emb(idx) <5> x_emb = x <...
===========below chunk 0=========== # module: RWKV-v5.src.model class RWKV(pl.LightningModule): def forward(self, idx): # offset: 1 x = self.head(x) + c else: x = self.head(x) return x ===========changed ref 0=========== ...
RWKV-v5.src.model/RWKV_Tmix_x070.__init__
Modified
BlinkDL~RWKV-LM
6b44d244e60143635c073507a4db4808b1731a32
less params for x070
<8>:<add> H = self.n_head <add> N = self.head_size <add> C = args.n_embd <12>:<add> ddd = torch.ones(1, 1, C) <del> ddd = torch.ones(1, 1, args.n_embd) <13>:<add> for i in range(C): <del> for i in range(args.n_embd): <14>:<add>...
# module: RWKV-v5.src.model ######################################################################################################## class RWKV_Tmix_x070(MyModule): def __init__(self, args, layer_id): <0> super().__init__() <1> self.args = args <2> self.l...
===========below chunk 0=========== # module: RWKV-v5.src.model ######################################################################################################## class RWKV_Tmix_x070(MyModule): def __init__(self, args, layer_id): # offset: 1 self.time_maa_a = nn.Param...
RWKV-v5.src.model/RWKV_Tmix_x070.forward
Modified
BlinkDL~RWKV-LM
6b44d244e60143635c073507a4db4808b1731a32
less params for x070
<18>:<add> v = v + (v0 - v) * torch.sigmoid(self.time_misc_v + (xv @ self.mv_w).view(B,T,H,1)).view(B,T,C) <del> v = v + (v0 - v) * torch.sigmoid(self.time_misc_v + (xv @ self.mv_w1) @ self.mv_w2) <19>:<add> a = torch.sigmoid(self.time_aaa + (xa @ self.time_aaa_w1) @ self.time_aaa_w...
<s>.n_embd**0.5)) + # self.value.weight.data.uniform_(-0.5/(C**0.5), 0.5/(C**0.5)) - # self.value.weight.data.uniform_(-0.5/(args.n_embd**0.5), 0.5/(args.n_embd**0.5)) # self.output.weight.data.zero_() @MyFunction def forward(self, x, v0...
===========below chunk 0=========== <s>**0.5)) + # self.value.weight.data.uniform_(-0.5/(C**0.5), 0.5/(C**0.5)) - # self.value.weight.data.uniform_(-0.5/(args.n_embd**0.5), 0.5/(args.n_embd**0.5)) # self.output.weight.data.zero_() @MyFunction def forw...
RWKV-v5.src.model/RWKV.generate_init_weight
Modified
BlinkDL~RWKV-LM
6b44d244e60143635c073507a4db4808b1731a32
less params for x070
<18>:<add> s3 = str(shape[3]) if len(shape) > 3 else "" <add> print(f"{s0.ljust(5)} {s1.ljust(5)} {s2.ljust(5)} {s3.ljust(5)} {n}", end="") <del> print(f"{s0.ljust(5)} {s1.ljust(5)} {s2.ljust(5)} {n}", end="")
# module: RWKV-v5.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): <0> print( <1> f""" <2> ############################################################################ <3> # <4> # Init model weight (slow for large models)... <5> # <6> ####...
===========below chunk 0=========== # module: RWKV-v5.src.model class RWKV(pl.LightningModule): def generate_init_weight(self): # offset: 1 scale = 0.5 * math.sqrt(self.args.vocab_size / self.args.n_embd) else: scale = 0.5 ...