File size: 1,912 Bytes
68888be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Options and results of answering, shared by the two ways of writing:
// real Kimi alone (reader_greedy) and draft and check (loop/draft_loop.h).
#pragma once

#include <functional>
#include <vector>

#include "reader/reader.h"

namespace hk {

struct DayOptions {
    int max_new = 256;                 // tokens to produce at most
    int max_rounds = 1000;             // safety cap on draft/check rounds
    std::vector<int32_t> stop_ids;     // generation ends after one of these
    int draft_len = 0;                 // tokens drafted per round; 0 = chosen each round (best_check_len)
    // What one more position adds to a sweep, as a share of a sweep over one position.
    // Only where the estimate starts (0 = 0.085): the loop corrects it from its own sweep times.
    double extra_cost = 0;
};

struct RoundInfo {
    int drafted = 0, accepted = 0;     // accepted: drafted tokens real Kimi let through
    bool fixed = false;
    double draft_seconds = 0, sweep_seconds = 0;
    int64_t sweep_bytes = 0;
};

struct DayResult {
    std::vector<int32_t> tokens;       // the continuation (prompt not included)
    std::vector<RoundInfo> rounds;
    int fixes = 0;
    bool stopped = false;              // ended on a stop token
    double seconds = 0, draft_seconds = 0, sweep_seconds = 0;
    int64_t sweep_bytes = 0;
};

struct DayCallbacks {
    std::function<void(const int32_t* tokens, int n)> on_approved;   // final tokens, in order
    std::function<void(const int32_t* tokens, int n)> on_draft;      // a fresh unverified draft (may be discarded)
};

// Greedy decoding with the reader alone, one sweep per token. Slow, but it is
// the ground truth the draft-and-check loop is tested against.
std::vector<int32_t> reader_greedy(Reader& reader, const std::vector<int32_t>& prompt, int max_new,
                                   const std::vector<int32_t>& stop_ids);

}  // namespace hk