model_factory.cpp 2.07 KB
Newer Older
1
2
3
4
#include "model_factory.hpp"
#include "llama/llama.hpp"

namespace infinilm {
5
6
7
8
9
10
11
12
13
14
15
16
/**
 * @deprecated This function is deprecated and will be REMOVED in the next major release (v0.2.0).
 *
 * ⚠️ DEVELOPMENT POLICY:
 *   - NO new development or feature additions permitted on this interface
 *   - Only critical bug fixes (security/stability) allowed until removal
 *   - All new code MUST migrate to the polymorphic overload below
 *
 * Replacement: Use the polymorphic overload of this same function name with updated signature
 * Reason: Legacy signature lacks support for dynamic quantization modes.
 * Removal target: v0.2.0 (Q2 2026)
 */
17
std::shared_ptr<InfinilmModel> InfinilmModelFactory::createModel(
Jiacheng Huang's avatar
Jiacheng Huang committed
18
    const InfinilmModel::Config &config,
19
    engine::distributed::RankInfo rank_info,
20
21
    const cache::CacheConfig *cache,
    backends::AttentionBackend attention_backend) {
PanZezhong's avatar
PanZezhong committed
22
    std::shared_ptr<InfinilmModel> model;
Jiacheng Huang's avatar
Jiacheng Huang committed
23
24
    if (const auto llama_config_ptr = dynamic_cast<const models::llama::LlamaConfig *>(&config)) {
        const auto &llama_config = *llama_config_ptr;
PanZezhong's avatar
PanZezhong committed
25
        model = std::make_shared<models::llama::LlamaForCausalLM>(
26
            llama_config, rank_info.device, rank_info, attention_backend);
27
28
29
    } else {
        throw std::invalid_argument("InfinilmModelFactory::createModel: Unsupported model config type");
    }
PanZezhong's avatar
PanZezhong committed
30
31
32
33
34
35

    if (cache) {
        model->reset_cache(cache);
    }

    return model;
36
}
37
38
39
40

std::shared_ptr<InfinilmModel> InfinilmModelFactory::createModel(
    std::shared_ptr<infinilm::config::ModelConfig> model_config,
    engine::distributed::RankInfo rank_info,
41
42
    const cache::CacheConfig *cache,
    backends::AttentionBackend attention_backend) {
43
44
45
46

    std::shared_ptr<InfinilmModel> model;
    if (true) {
        model = std::make_shared<models::llama::LlamaForCausalLM>(
47
            model_config, rank_info.device, rank_info, attention_backend);
48
49
50
51
52
53
54
55
56
57
    } else {
        throw std::invalid_argument("InfinilmModelFactory::createModel: Unsupported model config type");
    }

    if (cache) {
        model->reset_cache(cache);
    }

    return model;
}
58
} // namespace infinilm