Skip to content

[Fix] Reduce memory usage for loading llava model & Remove EntryClassRemapping - #1308

Merged
merrymercy merged 17 commits into
mainfrom
fix-llava
Sep 3, 2024
Merged

merrymercy merged 17 commits into
mainfrom
fix-llava

Conversation

@merrymercy

@merrymercy merrymercy commented Sep 3, 2024 •

Copy link
Copy Markdown
Collaborator
  • Reduce the CPU memory usage when loading llava model
  • Rename python/sglang/srt/models/llama2.py -> python/sglang/srt/models/llama.py
  • Remove EntryClassRemappling. We can favor explicit inherence.
  • Improve docs

@merrymercy merrymercy changed the title Misc fixes: Reduce the CPU memory usage when loading llava model [Fix] Reduce the CPU memory usage when loading llava model Sep 3, 2024
@merrymercy merrymercy changed the title [Fix] Reduce the CPU memory usage when loading llava model [Fix] Reduce memory usage for loading llava model & Remove EntryClassRemappling Sep 3, 2024
@merrymercy merrymercy changed the title [Fix] Reduce memory usage for loading llava model & Remove EntryClassRemappling [Fix] Reduce memory usage for loading llava model & Remove EntryClassRemapping Sep 3, 2024
@merrymercy
merrymercy merged commit f64eae3 into main Sep 3, 2024
@merrymercy
merrymercy deleted the fix-llava branch September 3, 2024 04:44
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…ot's cushion

Stage 2 wired cushion_headroom_gib into choose()'s ARM point, but
prior_cushion_min_gib/prior_bounce_gib were operator-typed only -- an INERT
gate, since nobody types two numbers by hand before a real boot, and the
next boot (BOOT7, d6c3d19) would never pass them.

Adds host_ledger.flip_ratchet_candidates()/resolve_prior_cushion(): every
FLIP-group sidecar entry of an EXACT form_key match (never newest-by-mtime --
sgl-project#1308's own shortcut cost two boots that way), taking the MINIMUM cushion_min
over those candidates (never the newest -- the direction is asymmetric, a
prior cushion read too high would loosen every boot after it, the sgl-project#782
ratchet-from-the-free-column class in the threshold direction). Both
cushion_min_gib and xchg_bounce_gib must come from the SAME candidate record,
never mixed across two boots that never coexisted.

front.py._write_flip_ratchet now also writes xchg_bounce_gib (from the same
ledger_arm dict dormant_image_sample already reads it from) beside the
existing cushion_min_gib field, so a future boot's record carries both halves
resolve_prior_cushion needs. flip_ratchet_record() gets the new optional
xchg_bounce_gib parameter (None-default, byte-identical for every existing
caller).

launcher.choose_host_ledger gains flip_ratchet_form_key (main passes
f"wtags={len(weights_tags)}", the exact literal front.py writes) and
self-resolves prior_cushion_min_gib/prior_bounce_gib from the sidecar unless
the operator's flags override them outright. A WEG2-CUSHION-HEADROOM-SOURCE
line is always appended -- auto-resolved, overridden, or "could not measure
(no candidate of this form / no form_key passed)" -- never silent. choose()
itself is unchanged from Stage 2.

Tests: test_weg2_cushion_headroom_autoresolve_1378_stage2b.py (12 cases) --
pure-resolver form/minimum correctness, front.py's one-producer wiring, and
end-to-end through the real choose_host_ledger seam (fake /proc/meminfo +
fake cgroup2 tree + a real sidecar file): no-flags-no-form-key is the
byte-identical Stage-2 default, form-key-alone auto-resolves, an explicit
flag overrides the sidecar (not the reverse), a foreign-form candidate never
wins through the real seam, and the minimum (not the newest) of several
same-form candidates wins through the real seam. Updated one Stage-2
structural test whose asserted forwarding text changed (raw params ->
resolved locals).

Manually verified both required danger-direction mutants: (1) min -> max in
resolve_prior_cushion: 2 of 12 tests go red (the two through-the-seam and
pure-resolver minimum tests); (2) the form_key equality filter dropped: 3 of
12 go red (the foreign-form and no-candidate-of-this-form tests). Both
restored, diff empty.

Regression run also caught and fixed a genuine bug this diff introduced:
test_weg2_flip_ratchet_1350.py's FrontEmitterSmoke1350._Stub lacked
ledger_arm, which a real Front always sets in __init__ -- AttributeError on
the new call site. Fixed by adding ledger_arm={} to the stub, matching the
real invariant, not by making front.py defensively getattr around a state a
real instance never lacks. 306 tests green across the wider weg2 regression
slice after the fix (previously-noted pre-existing failures in
test_weg2_run_residual_currency_1325.py confirmed unrelated by running
against the pristine pre-Stage-2b tip in a throwaway worktree, both same
three failures present there).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…ot's cushion

Stage 2 wired cushion_headroom_gib into choose()'s ARM point, but
prior_cushion_min_gib/prior_bounce_gib were operator-typed only -- an INERT
gate, since nobody types two numbers by hand before a real boot, and the
next boot (BOOT7, d6c3d19) would never pass them.

Adds host_ledger.flip_ratchet_candidates()/resolve_prior_cushion(): every
FLIP-group sidecar entry of an EXACT form_key match (never newest-by-mtime --
sgl-project#1308's own shortcut cost two boots that way), taking the MINIMUM cushion_min
over those candidates (never the newest -- the direction is asymmetric, a
prior cushion read too high would loosen every boot after it, the sgl-project#782
ratchet-from-the-free-column class in the threshold direction). Both
cushion_min_gib and xchg_bounce_gib must come from the SAME candidate record,
never mixed across two boots that never coexisted.

front.py._write_flip_ratchet now also writes xchg_bounce_gib (from the same
ledger_arm dict dormant_image_sample already reads it from) beside the
existing cushion_min_gib field, so a future boot's record carries both halves
resolve_prior_cushion needs. flip_ratchet_record() gets the new optional
xchg_bounce_gib parameter (None-default, byte-identical for every existing
caller).

launcher.choose_host_ledger gains flip_ratchet_form_key (main passes
f"wtags={len(weights_tags)}", the exact literal front.py writes) and
self-resolves prior_cushion_min_gib/prior_bounce_gib from the sidecar unless
the operator's flags override them outright. A WEG2-CUSHION-HEADROOM-SOURCE
line is always appended -- auto-resolved, overridden, or "could not measure
(no candidate of this form / no form_key passed)" -- never silent. choose()
itself is unchanged from Stage 2.

Tests: test_weg2_cushion_headroom_autoresolve_1378_stage2b.py (12 cases) --
pure-resolver form/minimum correctness, front.py's one-producer wiring, and
end-to-end through the real choose_host_ledger seam (fake /proc/meminfo +
fake cgroup2 tree + a real sidecar file): no-flags-no-form-key is the
byte-identical Stage-2 default, form-key-alone auto-resolves, an explicit
flag overrides the sidecar (not the reverse), a foreign-form candidate never
wins through the real seam, and the minimum (not the newest) of several
same-form candidates wins through the real seam. Updated one Stage-2
structural test whose asserted forwarding text changed (raw params ->
resolved locals).

Manually verified both required danger-direction mutants: (1) min -> max in
resolve_prior_cushion: 2 of 12 tests go red (the two through-the-seam and
pure-resolver minimum tests); (2) the form_key equality filter dropped: 3 of
12 go red (the foreign-form and no-candidate-of-this-form tests). Both
restored, diff empty.

Regression run also caught and fixed a genuine bug this diff introduced:
test_weg2_flip_ratchet_1350.py's FrontEmitterSmoke1350._Stub lacked
ledger_arm, which a real Front always sets in __init__ -- AttributeError on
the new call site. Fixed by adding ledger_arm={} to the stub, matching the
real invariant, not by making front.py defensively getattr around a state a
real instance never lacks. 306 tests green across the wider weg2 regression
slice after the fix (previously-noted pre-existing failures in
test_weg2_run_residual_currency_1325.py confirmed unrelated by running
against the pristine pre-Stage-2b tip in a throwaway worktree, both same
three failures present there).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant