File size: 861 Bytes
fae1252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    -- Ensemble gate (arbtok tools/build_ensemble_logits_onnx.py): where argmax(v2_logits) == 0,
    -- lift class 0 of the v3 value logits to v0 + relu(max - v0 + 1). ArgMax keeps the first maximum.
    local gated_logits = v3_value
    local n_cls = 75
    for t = 0, #tokens - 1 do
        local base = t * n_cls
        local g_best, g_arg = v2_logits[base + 1], 0
        local v_max = v3_value[base + 1]
        for c = 2, n_cls do
            local g = v2_logits[base + c]
            if g > g_best then g_best, g_arg = g, c - 1 end
            local v = v3_value[base + c]
            if v > v_max then v_max = v end
        end
        if g_arg == 0 then
            local v0 = v3_value[base + 1]
            local boost = v_max - v0 + 1.0
            if boost < 0 then boost = 0 end
            gated_logits[base + 1] = v0 + boost
        end
    end