For GPU tensors, we need to allocate them in VRAM as much as possible, and update the tensor data in-place. If the VRAM budget is exceeded, we allocate the tensor in CPU memory. Returns: equivalent of the model's n_gpu_layers
| 3046 | // we allocate the tensor in CPU memory. |
| 3047 | // Returns: equivalent of the model's n_gpu_layers |
| 3048 | int flush() { |
| 3049 | #if defined(GGML_USE_CUBLAS) |
| 3050 | if (!ggml_cublas_loaded()) { |
| 3051 | return 0; |
| 3052 | } |
| 3053 | |
| 3054 | // iterate over offloading priorities |
| 3055 | for (int enum_i = TENSOR_OFFLOAD_ATTN; enum_i <= TENSOR_OFFLOAD_OUTPUT; enum_i ++) { |
| 3056 | tensor_offloading_levels level = static_cast<tensor_offloading_levels>(enum_i); |
| 3057 | for (auto tensor_tup : alloc_queues[level]) { |
| 3058 | const int i_layer = std::get<0>(tensor_tup); |
| 3059 | const llm_tensor tensor_type = std::get<1>(tensor_tup); |
| 3060 | ggml_tensor * meta_tensor = std::get<2>(tensor_tup); |
| 3061 | if (!offload_tensor(meta_tensor)) { |
| 3062 | ml.done_getting_tensors(); |
| 3063 | return offloaded_layers; |
| 3064 | } |
| 3065 | |
| 3066 | if (level == TENSOR_OFFLOAD_ATTN && tensor_type == LLM_TENSOR_ATTN_OUT) { |
| 3067 | offloaded_layers = i_layer + 1; |
| 3068 | } else if (level == TENSOR_OFFLOAD_OUTPUT) { |
| 3069 | offloaded_layers = hparams.n_layer + 1; // indicate all layers + output are offloaded |
| 3070 | } |
| 3071 | } |
| 3072 | } |
| 3073 | ml.done_getting_tensors(); |
| 3074 | tensor_offload_complete = true; |
| 3075 | return offloaded_layers; |
| 3076 | #else // GGML_USE_CUBLAS |
| 3077 | return 0; |
| 3078 | #endif |
| 3079 | } |
| 3080 | }; |
| 3081 | |
| 3082 | static bool load_gpu_split_from_split_file(llama_model & model, std::string split_path, size_t vram_budget) { |
no test coverage detected