Experiment: lossless weight scheduling for models larger than RAM
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- 説明が足りない
- 活発さ
- 活発
- 技術スタック
- cpp, linux
- 領域
- ai, performance
調査の方向性
Start by reviewing the reported madvise experiments, the scheduled-streaming measurements, and the controlled fixed-kernel comparisons. A next step requires deciding whether this experimental direction belongs in dev and whether its controls should remain environment variables or become a memory-budget option; done is an agreed implementation scope and validation plan.
索引モデルが issue の本文から書いたものです。
説明
Hi @jan-wassenberg, following your suggestion in google/gemma.cpp#982,
I tested madvise policies for mapped weights and activations.
I tried the suggested advice modes and safe combinations: MADV_WILLNEED,
MADV_HUGEPAGE, MADV_POPULATE_READ, and MADV_COLLAPSE. Advice alone did
not produce a meaningful repeatable end-to-end gain. For example, activation
huge pages reduced minor faults but changed throughput by only about 0–1%, and
WILLNEED did not improve either 4B or 27B. I did not populate the entire 27B
mapping because that would force severe reclaim on this machine.
Here are my findings. The 27B test exposed a different problem: its 27.27 GiB
checkpoint has about 25.2 GiB of mapped weights active during text inference,
but the machine has 15.5 GiB RAM. Each token cycles through the weights,
evicting pages needed by the next token and rereading almost the entire active
set from storage.
I prototyped an opt-in, lossless policy:
- retain 8.45–8.81 GiB of exact weight copies across tokens;
- distribute the retained layers through the network;
- stream nonresident layers through two reusable
O_DIRECTbuffers; - read the next nonresident layer while the CPU computes the current layer;
- keep a memory-headroom guard and fall back to a smaller cache when needed.
No weight precision, batching, or decoding algorithm changes.
On an i5-12400F with 15.5 GiB RAM, medians of three interleaved cold runs with
Gemma 3 27B SFP, batch 1, and eight output tokens were:
| Measurement | mmap baseline | Scheduled streaming |
|---|---|---|
| Steady decode | 12.84 s/token | 4.18 s/token |
| Full request including load | 116.43 s | 48.05 s |
| Physical storage reads | 25.21 GiB/token | 16.75 GiB/token |
That is 3.07x faster steady decoding, 2.42x faster cold requests, and 33.6%
fewer physical reads. Controlled fixed-kernel runs matched baseline decode-logit
hashes exactly. The final normal-autotuning runs produced identical text, though
autotuning changes floating-point accumulation order even between baseline runs.
This is only intended for Linux systems where the model's active weights exceed
safe available RAM. Models that already fit, such as 4B on this machine, become
slower because explicit copying and streaming add overhead.
Would this experimental, opt-in direction be useful in dev? In particular,
feedback would be helpful on whether the controls should remain experimental
environment variables or become a smaller user-facing memory-budget option.
- 主要言語
- C++
- スター
- 7k
- フォーク
- 660
- 平均マージ
- 1日 3時間
- マージ済み PR(30日)
- 35
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
google/gemma.cpp のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
google/gemma.cpp の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
flutter-webrtc/flutter-webrtc#2206 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
Component: GLib
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
brave/brave-browser#59300 ·
-
Mute ydb/tests/functional/dstool/test_canonical_requests.py.Test.test_group_take_snapshot in main オープンai_reviewed
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
ydb-platform/ydb#53974 · コメント 3 件 ·