[BUG] Multi-GPU tensor-split offloads all physical layers to GPU0 on looped architectures

Đang mở
#206 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
58/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c, cpp
Lĩnh vực
backend

Hướng nghiên cứu

Start in src/llama-model.cpp at llama_model_base::create_tensor, where tn.bid (the GGUF physical block id) indexes pimpl->dev_layer, which is sized to n_layer_all; read loop_visit and loop_layer in the hparams/model code to confirm the mapping described. Apply the proposed change so the index goes through hparams.loop_visit(tn.bid) and check that non-looped models still get identity mapping. Done means a looped model loaded with --tensor-split places postlude blocks on the second GPU and no CUDA0 OOM occurs, which needs multi-GPU hardware.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

[BUG] Multi-GPU tensor-split offloads all physical layers to GPU0 on looped architectures

Description

When loading a looped model (such as Inkling-2-Mini, where 24 physical layers expand to 48 graph execution layers) with --tensor-split across multiple GPUs, all physical layers are erroneously assigned to device 0 (CUDA0), starving secondary GPUs (CUDA1) and causing an immediate out-of-memory crash:

ggml_backend_cuda_buffer_type_alloc_buffer: allocating 11383.97 MiB on device 0: cudaMalloc failed: out of memory
ggml_backend_buft_alloc_buffer_n_default: failed to allocate CUDA0 buffer of size 11936954112

Root Cause

  1. In GGUF files for looped models, physical layer blocks are numbered blk.0 to blk.23 (n_layer_weights = 24), whereas the graph execution sequence contains n_layer_all = 48 layers:

    • 0..5: prelude (physical 0..5)
    • 6..17: loop pass 0 (physical 6..17)
    • 18..29: loop pass 1 (physical 6..17)
    • 30..41: loop pass 2 (physical 6..17)
    • 42..47: postlude (physical 18..23)
  2. In llama_model_base::create_tensor:

    if (tn.bid != -1) {
        buft_list_layer = (size_t) tn.bid < pimpl->dev_layer.size() ? pimpl->dev_layer.at(tn.bid).buft_list : pimpl->dev_output.buft_list;
    }
    

    Here tn.bid is the physical block index in the GGUF file (0..23).
    pimpl->dev_layer is sized to n_layer_all (48), where pimpl->dev_layer[il] = get_layer_buft_list(loop_layer(il)).

    When create_tensor is called for postlude physical blocks 18..23:
    It indexes dev_layer.at(tn.bid), which evaluates to dev_layer.at(18..23).
    Because graph slots 18..23 are pass 1 of the looped core, loop_layer(18..23) maps to 6..11 (GPU0).
    Consequently, physical layers 18..23 (which were intended for GPU1) receive the device assignment of physical layers 6..11 (GPU0).
    Physical layers 0..17 are also mapped to 0..17 (GPU0).
    Thus, all 24 physical layers in the file are allocated on GPU0, regardless of --tensor-split.

Proposed Fix

In src/llama-model.cpp:
Map tn.bid to its canonical graph visit slot via hparams.loop_visit(tn.bid):

ggml_tensor * llama_model_base::create_tensor(llama_model_loader & ml, const LLM_TN_IMPL & tn, const std::initializer_list<int64_t> & ne, int flags) {
    const buft_list_t * buft_list_layer = nullptr;
    if (tn.bid != -1) {
        // blocks that are not model layers (e.g. the blocks of a head) go with the output
        const size_t iv = (size_t) hparams.loop_visit(tn.bid);
        buft_list_layer = iv < pimpl->dev_layer.size() ? pimpl->dev_layer.at(iv).buft_list : pimpl->dev_output.buft_list;
    }
    return ml.create_tensor(
        hparams, &pimpl->cpu_buft_list, pimpl->dev_input.buft_list, pimpl->dev_output.buft_list, buft_list_layer,
        tn, ne, flags);
}

For non-looped models, loop_visit(tn.bid) == tn.bid, preserving existing behavior.
For looped models, loop_visit(18..23) yields 42..47, correctly retrieving the device placement assigned to the postlude layers.

Ngôn ngữ chính
C++
Star
1.2k
Fork
80
Merge trung bình
4 ngày 20 giờ
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Anbeeld/beellama.cpp

Tất cả issue của Anbeeld/beellama.cpp

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.