MCPcopy Create free account
hub / github.com/andrewkchan/deepseek.cpp / InferenceState

Method InferenceState

src/model.cpp:677–726  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

675}
676
677InferenceState::InferenceState(const std::shared_ptr<Config> config):
678 _config(config) {
679 assert(config);
680 _x = new float[config->dim]();
681 _xb = new float[config->dim]();
682 _xb2 = new float[std::max({
683 config->dim,
684 config->n_heads * config->v_head_dim,
685 config->n_heads * config->kv_lora_rank
686 })]();
687 _hb = new float[std::max({
688 config->dim,
689 config->hidden_dim
690 })]();
691 _hb2 = new float[config->hidden_dim]();
692 if (config->q_lora_rank > 0) {
693 _q_a = new float[config->q_lora_rank]();
694 }
695 _q = new float[config->n_heads * config->head_dim]();
696 _kv_a = new float[config->kv_lora_rank + config->qk_rope_head_dim]();
697 _kv_b = new float[config->n_heads * (config->head_dim-config->qk_rope_head_dim+config->v_head_dim)]();
698 _ropebuf = new float[config->n_heads * config->qk_rope_head_dim]();
699 _k = new float[config->n_heads * config->head_dim]();
700 _v = new float[config->n_heads * config->v_head_dim]();
701 _att = new float[config->n_heads * config->max_seq_len]();
702 _logits = new float[config->vocab_size]();
703 _logit_indices = new int[config->vocab_size]();
704 for (int i = 0; i < config->vocab_size; i++){
705 _logit_indices[i] = i;
706 }
707 if (config->use_mla) {
708 _q_c = new float[config->n_heads * config->kv_lora_rank]();
709 _q_rope = new float[config->n_heads * config->qk_rope_head_dim]();
710 }
711 if (config->n_routed_experts > 0) {
712 _moe_weights = new float[config->n_routed_experts]();
713 _active_experts = new int[config->n_active_routed]();
714 _active_experts_weights = new float[config->n_active_routed]();
715 }
716 // TODO: consider dynamically resizing based on inputs
717 size_t aqb_nitems = std::max({
718 config->dim,
719 config->moe_intermediate_size,
720 config->n_heads * config->v_head_dim,
721 config->n_heads * config->kv_lora_rank,
722 config->hidden_dim
723 });
724 size_t aqb_nblocks = aqb_nitems / QK_K;
725 _aqb = new uint8_t[aqb_nblocks * sizeof(block_q8_K)]();
726}
727
728InferenceState::~InferenceState() {
729 if (_device == Device::CPU) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected