The flow instance (docs/roleflow.tex, sec:flow; module Flow) #
A sort is a dimension n with a reference measure on Vec n: Lebesgue (vec n, data), the
standard normal (gauss n, randomness) or the standard logistic (unit n, a point of
(0, 1)ⁿ in its logit chart). The operations are those of
SemiInv2's flow signature, flat: arguments and results are separate variables.
Each operation has at most one semi-inverse, which solves its first argument (or, for
split/concat, all of them). An inverse pair is one constructor with a flag inv, and the
semi-inverse flips it:
| operation | inv = false | inv = true | log-weight |
|---|---|---|---|
add | x + q | x - q (sub) | 0 |
scaleexp | x ⊙ e^s | x ⊙ e^{-s} (scalenexp) | ±Σ s |
triu (Glow's LU factors) | M x | M⁻¹ x | ±triuLogdet U |
oddpow k | x ^ (2k+1) | y ^ (1/(2k+1)) | opowLogdet k x, -opowLogdet k (y ^ (1/(2k+1))) |
The other pairs are perm ps/perm ps⁻¹ (a permutation given by its steps, Flow.PermS; its
index map is read as an Equiv.Perm by permOf), split/concat (log-weight 0), and
rebase r r'/rebase r' r, the identity from the sort (r, n) to (r', n) with log-weight
log ρ_{r'} - log ρ_r (score, sample, sigmoid and logit against Lebesgue measure).
The conditioners (mvmul, mul, relu, conv3x3, attend, …) have none.
The model flowModel is a ModelInv. Leaves are proved at one flag (by measure preservation,
the Jacobian formula or a density) and derived at the other by leaf_dag, whose derived
log-weight agrees with the one given here; rebase has one leaf for all pairs of measures.
Every declared pair is mutual, so the right law of an operation is the left law of its
semi-inverse.
Sorts #
Equations
- RoleFlow.Flow.instReprRef.repr RoleFlow.Flow.Ref.leb prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "RoleFlow.Flow.Ref.leb")).group prec✝
- RoleFlow.Flow.instReprRef.repr RoleFlow.Flow.Ref.normal prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "RoleFlow.Flow.Ref.normal")).group prec✝
- RoleFlow.Flow.instReprRef.repr RoleFlow.Flow.Ref.logistic prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "RoleFlow.Flow.Ref.logistic")).group prec✝
Instances For
Equations
- RoleFlow.Flow.instReprRef = { reprPrec := RoleFlow.Flow.instReprRef.repr }
The log-density of the reference measure against Lebesgue measure.
Equations
- RoleFlow.Flow.Ref.leb.logpdf x✝ = fun (x : RoleFlow.Flow.Vec x✝) => 0
- RoleFlow.Flow.Ref.normal.logpdf x✝ = fun (x : RoleFlow.Flow.Vec x✝) => Real.log (RoleFlow.Flow.stdNormalPDF x✝ x)
- RoleFlow.Flow.Ref.logistic.logpdf x✝ = fun (x : RoleFlow.Flow.Vec x✝) => Real.log (RoleFlow.Flow.logisticPDF x✝ x)
Instances For
The sorts: a reference measure and a dimension.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- RoleFlow.Flow.instReprFS = { reprPrec := RoleFlow.Flow.instReprFS.repr }
Data.
Equations
- RoleFlow.Flow.FS.vec n = { ref := RoleFlow.Flow.Ref.leb, dim := n }
Instances For
Standard-normal randomness.
Equations
- RoleFlow.Flow.FS.gauss n = { ref := RoleFlow.Flow.Ref.normal, dim := n }
Instances For
Points of the unit cube in their logit chart.
Equations
- RoleFlow.Flow.FS.unit n = { ref := RoleFlow.Flow.Ref.logistic, dim := n }
Instances For
Equations
- One or more equations did not get rendered due to their size.
Operations #
The flow operations, flat. The flag inv selects the second operation of an inverse
pair.
- nil : FOp [] [FS.vec 0]
The empty vector (the initial key-value cache).
- split (m n : ℕ) : FOp [FS.vec (m + n)] [FS.vec m, FS.vec n]
- concat (m n : ℕ) : FOp [FS.vec m, FS.vec n] [FS.vec (m + n)]
- perm
(n : ℕ)
(ps : PermS)
(inv : Bool := false)
: FOp [FS.vec n] [FS.vec n]
The permutation
ps(its inverse ifinv): output entryiis input entryps.idx i. - rebase
(r r' : Ref)
(n : ℕ)
: FOp [{ ref := r, dim := n }] [{ ref := r', dim := n }]
The identity, from the reference measure
rtor'. - relu (n : ℕ) : FOp [FS.vec n] [FS.vec n]
- tanh (n : ℕ) : FOp [FS.vec n] [FS.vec n]
- layernorm (n : ℕ) : FOp [FS.vec n] [FS.vec n]
- gelu (n : ℕ) : FOp [FS.vec n] [FS.vec n]
- oddpow
(n k : ℕ)
(inv : Bool := false)
: FOp [FS.vec n] [FS.vec n]
x ↦ x ^ (2k + 1), elementwise;y ↦ y ^ (1/(2k + 1))(the odd real root) ifinv. - rows2 (m n : ℕ) : FOp [FS.vec ((m + m) * n)] [FS.vec (m * n), FS.vec (m * n)]
- add
(n : ℕ)
(inv : Bool := false)
: FOp [FS.vec n, FS.vec n] [FS.vec n]
x + q;x - qifinv. - scaleexp
(n : ℕ)
(inv : Bool := false)
: FOp [FS.vec n, FS.vec n] [FS.vec n]
x ⊙ exp s;x ⊙ exp (-s)ifinv. - triu
(c n : ℕ)
(inv : Bool := false)
: FOp [FS.vec (c * n), FS.vec (c * c)] [FS.vec (c * n)]
M x(triuMat),M⁻¹ xifinv: with channel permutations, Glow's LU 1 × 1 convolution. - mvmul
(m n : ℕ)
: FOp [FS.vec (m * n), FS.vec n] [FS.vec m]
W · xfor a row-majorm × nmatrixW. - mul
(n : ℕ)
: FOp [FS.vec n, FS.vec n] [FS.vec n]
x ⊙ y, elementwise. - addc
(c h w : ℕ)
: FOp [FS.vec (c * (h * w)), FS.vec c] [FS.vec (c * (h * w))]
A per-channel bias.
- conv1x1
(cin cout h w : ℕ)
: FOp [FS.vec (cout * cin), FS.vec (cin * (h * w))] [FS.vec (cout * (h * w))]
Kernel first, then the image.
- conv3x3 (cin cout h w : ℕ) : FOp [FS.vec (cout * (cin * 9)), FS.vec (cin * (h * w))] [FS.vec (cout * (h * w))]
- attend
(m h : ℕ)
: FOp [FS.vec h, FS.vec (h * m), FS.vec (h * m)] [FS.vec h]
A query against a key-value cache.
Instances For
Names for the flipped flags and the changes of sort that the models use.
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
The declared semi-inverses.
Equations
- (RoleFlow.Flow.FOp.split m n).inv = some { cs := [RoleFlow.Flow.FS.vec (m + n)], ps := [], split := ⋯, cs_ne := ⋯, op := RoleFlow.Flow.FOp.concat m n }
- (RoleFlow.Flow.FOp.concat m n).inv = some { cs := [RoleFlow.Flow.FS.vec m, RoleFlow.Flow.FS.vec n], ps := [], split := ⋯, cs_ne := ⋯, op := RoleFlow.Flow.FOp.split m n }
- (RoleFlow.Flow.FOp.perm n ps inv).inv = some (RoleFlow.Flow.si0 (RoleFlow.Flow.FOp.perm n ps !inv))
- (RoleFlow.Flow.FOp.rebase r r' n).inv = some (RoleFlow.Flow.si0 (RoleFlow.Flow.FOp.rebase r' r n))
- (RoleFlow.Flow.FOp.oddpow n k inv).inv = some (RoleFlow.Flow.si0 (RoleFlow.Flow.FOp.oddpow n k !inv))
- (RoleFlow.Flow.FOp.add n inv).inv = some (RoleFlow.Flow.si1 (RoleFlow.Flow.FOp.add n !inv))
- (RoleFlow.Flow.FOp.scaleexp n inv).inv = some (RoleFlow.Flow.si1 (RoleFlow.Flow.FOp.scaleexp n !inv))
- (RoleFlow.Flow.FOp.triu c n inv).inv = some (RoleFlow.Flow.si1 (RoleFlow.Flow.FOp.triu c n !inv))
- x✝.inv = none
Instances For
The flow signature.
Equations
- RoleFlow.Flow.flowSig = { Op := RoleFlow.Flow.FOp, bs_ne := @RoleFlow.Flow.flowSig._proof_1, inv := fun {as bs : List RoleFlow.Flow.FS} => RoleFlow.Flow.FOp.inv }
Instances For
Tuples #
A one-element tuple.
Equations
Instances For
A two-element tuple.
Equations
- RoleFlow.Flow.two x y = RoleFlow.Val.cons x (RoleFlow.Flow.one y)
Instances For
The model #
t, or -t if inv.
Equations
- RoleFlow.Flow.negIf false x✝ = x✝
- RoleFlow.Flow.negIf true x✝ = -x✝
Instances For
The permutation of Fin n whose index map is ps.idx (taken mod n), if that map is
injective; otherwise the identity. A PermS.valid permutation is one, but nothing here needs it:
every operation is interpreted, and Print.certify refuses invalid ones.
Equations
- RoleFlow.Flow.permS n ps = if h : Function.Injective fun (i : Fin n) => ⟨ps.idx ↑i % n, ⋯⟩ then Equiv.ofBijective (fun (i : Fin n) => ⟨ps.idx ↑i % n, ⋯⟩) ⋯ else Equiv.refl (Fin n)
Instances For
perm n ps inv as a permutation of the entries.
Equations
- RoleFlow.Flow.permOf n ps inv = if inv = true then Equiv.symm (RoleFlow.Flow.permS n ps) else RoleFlow.Flow.permS n ps
Instances For
The interpretation of the operations.
Equations
- One or more equations did not get rendered due to their size.
- RoleFlow.Flow.semOp RoleFlow.Flow.FOp.nil = fun (x : RoleFlow.Val []) => RoleFlow.Flow.one Fin.elim0
- RoleFlow.Flow.semOp (RoleFlow.Flow.FOp.concat m n) = fun (v : RoleFlow.Val [RoleFlow.Flow.FS.vec m, RoleFlow.Flow.FS.vec n]) => RoleFlow.Flow.one (RoleFlow.Flow.vjoin v.head v.tail.head)
- RoleFlow.Flow.semOp (RoleFlow.Flow.FOp.rebase r r' n) = fun (v : RoleFlow.Val [{ ref := r, dim := n }]) => RoleFlow.Flow.one v.head
- RoleFlow.Flow.semOp (RoleFlow.Flow.FOp.relu n) = fun (v : RoleFlow.Val [RoleFlow.Flow.FS.vec n]) => RoleFlow.Flow.one (RoleFlow.Flow.fvrelu v.head)
- RoleFlow.Flow.semOp (RoleFlow.Flow.FOp.tanh n) = fun (v : RoleFlow.Val [RoleFlow.Flow.FS.vec n]) => RoleFlow.Flow.one (RoleFlow.Flow.fvtanh v.head)
- RoleFlow.Flow.semOp (RoleFlow.Flow.FOp.layernorm n) = fun (v : RoleFlow.Val [RoleFlow.Flow.FS.vec n]) => RoleFlow.Flow.one (RoleFlow.Flow.flayernorm v.head)
- RoleFlow.Flow.semOp (RoleFlow.Flow.FOp.gelu n) = fun (v : RoleFlow.Val [RoleFlow.Flow.FS.vec n]) => RoleFlow.Flow.one (RoleFlow.Flow.fgelu v.head)
Instances For
The log-weights, on the whole argument tuple; 0 for the structural bijections and for
the conditioners.
Equations
- One or more equations did not get rendered due to their size.
- RoleFlow.Flow.ℓOp (RoleFlow.Flow.FOp.rebase r r' n) = fun (v : RoleFlow.Val [{ ref := r, dim := n }]) => r'.logpdf n v.head - r.logpdf n v.head
- RoleFlow.Flow.ℓOp x✝ = fun (x : RoleFlow.Val x✝²) => 0
Instances For
Measurability #
Laws #
The left law of o with the semi-inverse si.
Equations
- RoleFlow.Flow.LeftLaw o si = ∀ (c : RoleFlow.Val si.cs) (p : RoleFlow.Val si.ps), RoleFlow.Flow.semOp si.op ((RoleFlow.Flow.semOp o (si.glue c p)).append p) = c
Instances For
The left law of an operation that consumes its first argument.
Leaves #
Change of variables on one value, carried to one-element contexts.
Derived leaves #
The leaf of a semi-inverse, derived by leaf_dag from the leaf and the left law of the
operation it inverts; the derived log-weight is checked against ℓOp.
Right laws #
The model of the flow signature.
Equations
- One or more equations did not get rendered due to their size.