Cache get_config by model_name#38
Merged
Merged
Conversation
get_config() opens and parses configs/model/<model_name>.json on every call with no caching. calculate_sizes() (memory_model.py:797) calls get_config() unconditionally as its first line, and is itself called ~20-30 times per scheduler iteration (per layer, once directly from _emit_layer and once indirectly via XPURooflineModel._traffic_bytes). For a 129-iter --analytical-modeling baseline on Llama-3.1-8B, this showed up in the pyinstrument profile as ~100 ms across the calculate_sizes / _resolve_layer_latency call sites — same pattern as the _load_architecture (PR #36) and inline-chakra (PR #37) fixes. Adds a small module-level _config_cache mirroring _arch_cache / _perf_db_cache in trace_generator.py. Wall-clock on 129-iter baseline (5 runs, mean ± stdev): before: 1.57 s ± 0.06 after: 1.36 s ± 0.05 (-210 ms, -13%) Sim-time output (Total clocks, Mean TTFT/TPOT/ITL) unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_config()(serving/core/utils.py:58) opens and parsesconfigs/model/<model_name>.jsonon every call with no caching.calculate_sizes()(serving/core/memory_model.py:797) callsget_config()unconditionally as its first line, and is itself called ~20-30 times per scheduler iteration -- once directly from_emit_layerand once indirectly viaXPURooflineModel._traffic_bytes-- so each iteration was re-reading the sameLlama-3.1-8B.json(or whichever model) from disk many times.This patch adds a small module-level
_config_cachekeyed bymodel_name, mirroring the existing_arch_cache/_perf_db_cachepattern inserving/core/trace_generator.py(PRs #36 / #37 fixed the same shape of bug for the architecture yaml and chakra subprocess).Measurement
Setup:
NUM_REQ=4 PROMPT_LEN=128 OUTPUT_LEN=128 ./serving/spec_compression_stress.sh baseline(129 scheduler iterations, Llama-3.1-8B,--analytical-modeling).Wall-clock (5 runs each, after warmup):
-> -210 ms (-13%) on this workload.
pyinstrument breakdown of
generate_trace(the affected path):_build_transformer_block_emit_pre_attn_layers._emit_layercalculate_sizes/get_config)_resolve_layer_latency->_traffic_bytes->calculate_sizes_emit_final_layersTotal clocks (ns)(144012083on the 33-iter run,579297238on the 129-iter run) andMean TTFT / TPOT / ITLare bit-identical before and after.The cache key is
model_nameonly and the JSON on disk is read-only during a simulation run, so there is no invalidation concern. Multi-instance runs that share a model share the parsed dict.Test plan
NUM_REQ=2 PROMPT_LEN=64 OUTPUT_LEN=32 ./serving/spec_compression_stress.sh baseline--Total clocks = 144012083unchanged across 3 runsNUM_REQ=4 PROMPT_LEN=128 OUTPUT_LEN=128 ./serving/spec_compression_stress.sh baseline--Total clocks = 579297238unchanged across 2 runs; -13% wall-clockself_verify/cpu_verifymodesGenerated by Claude Code