infinilm_model.hpp 1.08 KB
Newer Older
1
2
3
4
#pragma once

#include "infinicore/nn/module.hpp"

5
6
#include "../cache/cache.hpp"

7
8
9
10
11
#include <any>

namespace infinilm {
class InfinilmModel : public infinicore::nn::Module {
public:
Jiacheng Huang's avatar
Jiacheng Huang committed
12
13
14
15
16
17
    struct Config {
        std::string model_type;

        virtual ~Config() = default;
    };

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
    struct Input {
        /// Token IDs tensor of shape `[batch, seq_len]`.
        infinicore::Tensor input_ids;

        /// Position IDs tensor of shape `[batch, seq_len]` or `[seq_len]`.
        infinicore::Tensor position_ids;

        /// Optional model-level KV cache for incremental decoding. Defaults to `nullptr`.
        void *kv_cache = nullptr;
    };

    struct Output {
        /// Output tensor of shape [batch, seq_len, vocab_size].
        infinicore::Tensor logits;
    };

34
    virtual ~InfinilmModel() = default;
35
    virtual Output forward(const Input &input) const = 0;
Ceng's avatar
Ceng committed
36
37
    // Optional: reset cache; default no-op for models without cache
    virtual void reset_cache(size_t pos = 0) {}
38
    virtual void reset_cache(const cache::CacheConfig &new_config, size_t pos = 0) = 0;
39
40
};
} // namespace infinilm