Implement the Gated DeltaNet recurrent update. At position t, qt, kt, and vt are query, normalized key, and value vectors; γt and βt are scalar decay and update gates. St is the state, yt is the output, and I is the Dk-by-Dk identity matrix. Superscript T denotes transpose.
St=γt(I−βtktktT)St−1+βtktvtT. yt=qtTSt.Each batch state starts at zero. Return a dictionary containing outputs with shape (B, S, Dv) and final_state with shape (B, Dk, Dv), both PyTorch tensors with the same dtype and device as q.
Input: q = [[[1,0],[1,0]]], k = [[[1,0],[1,0]]], v = [[[2,0],[5,0]]], gamma = [[1,1]], beta = [[1,1]]
Output: {"outputs":[[[2,0],[5,0]]],"final_state":[[[5,0],[0,0]]]}
Explanation: The repeated unit key erases its previous state direction before the second value is written, so 5 replaces 2.
Input: q = [[[1,0],[1,0]]], k = [[[1,0],[1,0]]], v = [[[4,0],[99,0]]], gamma = [[1,0.5]], beta = [[1,0]]
Output: {"outputs":[[[4,0],[2,0]]],"final_state":[[[2,0],[0,0]]]}
Input: q = [[[1,0]],[[0,1]]], k = [[[1,0]],[[0,1]]], v = [[[7]],[[9]]], gamma = [[1],[1]], beta = [[1],[1]]
Output: {"outputs":[[[7]],[[9]]],"final_state":[[[7],[0]],[[0],[9]]]}
torch.eye creates the identity matrix on a chosen device.
torch.bmm applies a different matrix to each batch item.
torch.unsqueeze supports batched outer products through broadcasting.
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Implement the Gated DeltaNet recurrent update. At position t, qt, kt, and vt are query, normalized key, and value vectors; γt and βt are scalar decay and update gates. St is the state, yt is the output, and I is the Dk-by-Dk identity matrix. Superscript T denotes transpose.
St=γt(I−βtktktT)St−1+βtktvtT. yt=qtTSt.Each batch state starts at zero. Return a dictionary containing outputs with shape (B, S, Dv) and final_state with shape (B, Dk, Dv), both PyTorch tensors with the same dtype and device as q.
Input: q = [[[1,0],[1,0]]], k = [[[1,0],[1,0]]], v = [[[2,0],[5,0]]], gamma = [[1,1]], beta = [[1,1]]
Output: {"outputs":[[[2,0],[5,0]]],"final_state":[[[5,0],[0,0]]]}
Explanation: The repeated unit key erases its previous state direction before the second value is written, so 5 replaces 2.
Input: q = [[[1,0],[1,0]]], k = [[[1,0],[1,0]]], v = [[[4,0],[99,0]]], gamma = [[1,0.5]], beta = [[1,0]]
Output: {"outputs":[[[4,0],[2,0]]],"final_state":[[[2,0],[0,0]]]}
Input: q = [[[1,0]],[[0,1]]], k = [[[1,0]],[[0,1]]], v = [[[7]],[[9]]], gamma = [[1],[1]], beta = [[1],[1]]
Output: {"outputs":[[[7]],[[9]]],"final_state":[[[7],[0]],[[0],[9]]]}
torch.eye creates the identity matrix on a chosen device.
torch.bmm applies a different matrix to each batch item.
torch.unsqueeze supports batched outer products through broadcasting.
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array