model_factory.cpp 1.93 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,
PanZezhong's avatar
PanZezhong committed
20
21
    const cache::CacheConfig *cache) {
    std::shared_ptr<InfinilmModel> model;
Jiacheng Huang's avatar
Jiacheng Huang committed
22
23
    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
24
        model = std::make_shared<models::llama::LlamaForCausalLM>(
25
            llama_config, rank_info.device, rank_info);
26
27
28
    } else {
        throw std::invalid_argument("InfinilmModelFactory::createModel: Unsupported model config type");
    }
PanZezhong's avatar
PanZezhong committed
29
30
31
32
33
34

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

    return model;
35
}
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

std::shared_ptr<InfinilmModel> InfinilmModelFactory::createModel(
    std::shared_ptr<infinilm::config::ModelConfig> model_config,
    engine::distributed::RankInfo rank_info,
    const cache::CacheConfig *cache) {

    std::shared_ptr<InfinilmModel> model;
    if (true) {
        model = std::make_shared<models::llama::LlamaForCausalLM>(
            model_config, rank_info.device, rank_info);
    } else {
        throw std::invalid_argument("InfinilmModelFactory::createModel: Unsupported model config type");
    }

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

    return model;
}
56
} // namespace infinilm