MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / apply

Method apply

subprojects/llama.cpp/src/llama-adapter.cpp:94–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

ggml_backend_tensor_setFunction · 0.85
ggml_element_sizeFunction · 0.85
emptyMethod · 0.65
initFunction · 0.50

Tested by

no test coverage detected