| 2470 | out.unconditional_logits.resize(static_cast<size_t>(config.vocab_size)); |
| 2471 | ggml_backend_tensor_get( |
| 2472 | logits_cond_, |
| 2473 | out.conditional_logits.data(), |
| 2474 | 0, |
| 2475 | out.conditional_logits.size() * sizeof(float)); |
| 2476 | ggml_backend_tensor_get( |
| 2477 | logits_uncond_, |
| 2478 | out.unconditional_logits.data(), |
| 2479 | 0, |
| 2480 | out.unconditional_logits.size() * sizeof(float)); |
| 2481 | if (runtime_->backend_type() == core::BackendType::Cuda) { |
| 2482 | const auto shape = core::TensorShape::from_dims({1, prompt_steps_, config.num_key_value_heads, config.head_dim}); |
| 2483 | for (size_t layer = 0; layer < key_cond_outputs_.size(); ++layer) { |
| 2484 | out.device_keys[0].push_back(core::wrap_tensor(key_cond_outputs_[layer], shape, GGML_TYPE_F16)); |
| 2485 | out.device_keys[1].push_back(core::wrap_tensor(key_uncond_outputs_[layer], shape, GGML_TYPE_F16)); |
| 2486 | out.device_values[0].push_back(core::wrap_tensor(value_cond_outputs_[layer], shape, GGML_TYPE_F16)); |
| 2487 | out.device_values[1].push_back(core::wrap_tensor(value_uncond_outputs_[layer], shape, GGML_TYPE_F16)); |
| 2488 | } |
| 2489 | return out; |
| 2490 | } |
| 2491 | out.layers.resize(keys_.size()); |
| 2492 | const size_t branch_values = static_cast<size_t>(prompt_steps_ * config.num_key_value_heads * config.head_dim); |
| 2493 | for (size_t layer = 0; layer < key_cond_outputs_.size(); ++layer) { |
| 2494 | auto & state = out.layers[layer]; |
| 2495 | state.key.resize(2 * branch_values); |
| 2496 | state.value.resize(2 * branch_values); |
| 2497 | ggml_backend_tensor_get(key_cond_outputs_[layer], state.key.data(), 0, branch_values * sizeof(float)); |
| 2498 | ggml_backend_tensor_get( |
| 2499 | key_uncond_outputs_[layer], |
| 2500 | state.key.data() + static_cast<std::ptrdiff_t>(branch_values), |
| 2501 | 0, |
| 2502 | branch_values * sizeof(float)); |
| 2503 | ggml_backend_tensor_get(value_cond_outputs_[layer], state.value.data(), 0, branch_values * sizeof(float)); |
| 2504 | ggml_backend_tensor_get( |
| 2505 | value_uncond_outputs_[layer], |
| 2506 | state.value.data() + static_cast<std::ptrdiff_t>(branch_values), |
| 2507 | 0, |
| 2508 | branch_values * sizeof(float)); |
no test coverage detected