MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / apply

Method apply

smallthinker/src/llama-adapter.cpp:93–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91}
92
93bool llama_adapter_cvec::apply(
94 const llama_model & model,
95 const float * data,
96 size_t len,
97 int32_t n_embd,
98 int32_t il_start,
99 int32_t il_end) {
100 const auto & hparams = model.hparams;
101
102 if (data == nullptr) {
103 // disable the current control vector (but leave allocated for later)
104 layer_start = -1;
105 layer_end = -1;
106 return true;
107 }
108
109 if (n_embd != (int) hparams.n_embd) {
110 LLAMA_LOG_ERROR("%s: control vector n_embd does not match model\n", __func__);
111 return false;
112 }
113
114 if (tensors.empty()) {
115 if (!init(model)) {
116 return false;
117 }
118 }
119
120 layer_start = il_start;
121 layer_end = il_end;
122
123 for (size_t il = 1; il < hparams.n_layer; il++) {
124 assert(tensors[il] != nullptr);
125
126 const size_t off = n_embd * (il - 1); // buffer doesn't have data for layer 0, since it's never present
127 if (off + n_embd <= len) {
128 ggml_backend_tensor_set(tensors[il], data + off, 0, n_embd * ggml_element_size(tensors[il]));
129 }
130 }
131
132 return true;
133}
134
135// lora
136

Callers 8

llama_sampler_applyFunction · 0.45
apply_adapter_cvecMethod · 0.45
process_ubatchMethod · 0.45
opt_epoch_iterMethod · 0.45
applyFunction · 0.45
LLamaAndroidClass · 0.45
onClickMethod · 0.45
tnFunction · 0.45

Calls 4

initFunction · 0.50
ggml_backend_tensor_setFunction · 0.50
ggml_element_sizeFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected