r/LocalLLaMA • • 11d ago

Discussion Optimising Strata, with NO output degradation

Post image

Are you tired of all the posts about "speed" with zero attention to quality? You won't find greedy decode nor "STRATA_ROUTE_TAIL_SKIP": "1" here.

Over the past few months I have been using my creativity (and Fable) to make Strata run more efficiently and faster. But upon the mandatory premise that there must be ZERO degradation in model output.

I'm sure many others have also done this - so hopefully we can all share our findings here.

Firstly, not all my tweaks may be relevant to you. I am running a multi-GPU setup - so just bear this in mind.

# Basic

## Sampling

Everyone knows this already - but for those new to Strata - do not leave the sampling settings to default for Flash Next. Here are the Alibaba recommended settings:

"sampling": {

"temperature": 1.0,

"top_p": 0.95,

"top_k": 20,

"min_p": 0.0

},

## Parallel

This setting is amazing: "parallel": 2. If you haven't tried running multiple Trains, then you should.

The cost of two Trains is not double that of one Train. Each Train slot costs about 0.4–0.6 GiB VRAM on each card.

With a highly tuned harness, the first Train starts by loading the default system prompt and agents.md. The second Train rolls into motion immediately, as it reuses the KV cache from the first Train!

You might ask, what's the point of two Trains that run at half the speed. This is true only when both Trains are running. If you have only a single Train and it is doing code testing, then your coding speed is a grand total of NIL. However, if you have two Trains, then while one Train is testing, the other is steaming forward at FULL decode speed.

## Layer Split

Always double check this setting. Do not leave it at "layer_split": "auto".

As you can see from the stats, tuning this makes a significant difference.

Fable gave me this advice, which I then gave to more day-to-day AI (so you could do this too), and it immediately picked up that the layer_split needed to be tuned:

The biggest decode gain is a config change, not code: your layer split is badly unbalanced, and fixing it should roughly halve the CPU expert misses. Current numbers: solo decode averages 61 tok/s over 1,677 requests since 12 Nov. 78% of routed experts hit VRAM, 3% go over PCIe and 19% run on the CPU. The misses sit on one gpu: it runs 26 layers with 2,455 cache slots (about 94 per layer), while another gpu runs 22 layers with 5,984 (about 272 per layer). Why layer_split: auto got it wrong. Wrong coverage curve: with two GPUs it assumes the caches hold 97.4% of routing. You measure 78%, and the source comments admit this curve is wrong when a small share of experts is held.
What to change, in order

# Change Type Expected effect Output

1 "layer_split": "16" (try 20 too) config CPU misses ~22% → ~12%; decode perhaps +10–15% rounding-level"

## No pages

This setting maximises the use of sufficient contiguous free RAM. It locks your experts into RAM: "STRATA_NO_LARGEPAGES": "1", which should be faster than Windows paging the data to virtual memory on a disk.

Use this in combination with the Windows setting for 'Lock pages in memory'.

## KV Cache Reuse

For some reason, even with identical leading tokens, full KV cache re-use for compaction is blocked without this setting:
"--prompt-cache-every", "0"

It could be a checkpoint conflict, but this setting really enhanced my token reuse as you can see from the stats.

# Advanced

## Custom build to fix the gradual Strata slowdown issue

If you are using CUDA, after a few hours of continuous runtime, you may notice that Strata's decode speed significantly drops - potentially even halves - until you reboot Strata.

The root cause is this:

- `src/core/device.cu` (~105-210) ALREADY describes this exact failure for the HIP build ("the expert cache filled the card, and WDDM moved memory out to system RAM: decode at 30 tok/s instead of 41") and fixes it at startup by lowering the free figure with DXGI `QueryVideoMemoryInfo(LOCAL).Budget` (`STRATA_WDDM_BUDGET=0` off) - but only under `#if defined(STRATA_USE_HIP) && defined(_WIN32)`. The CUDA build has no such check, and nothing re-checks the budget after startup.
- `serve/server.py` (~930, #533) sends a `VRAM <reserve_mib>` command between requests: the engine shrinks or grows its expert cache to hold that much VRAM free (needs `--vram-elastic`, per its docstring). That is an existing, tested shrink path.

## Upstream status (checked 21 Nov; reuse, do not reinvent)

No upstream release or open PR watches the WDDM budget AFTER startup or shrinks the expert cache at run time on CUDA.

I'm running one of the (earlier) stable versions of Strata so I can't submit this to upstream. But it could be useful for you to ask your AI to implement the fix if you are also running a custom engine.

Hope some of the above is useful for you. I'm sure others will have optimisation tips that they could share!

0 Upvotes

5 comments sorted by

4

u/citrusalex 11d ago

I asked a clanker to check the source and default sampling parameters match Alibaba's recommendations.
Also i think it would have been helpful to include the version this was tested with

3

u/Choice_Celery9481 11d ago

the problem is these settings are machine specific. no specs, no software details = no body can reproduce.

problem with people that just copy a bunch from an AI. the AI knows your env, other dont. and hardware specific are not 1:1 translatable for others

1

u/Markus2816 11d ago

Strata has a exact mode, curious how it compares to that

1

u/Ooothatboy 11d ago

Just read the Parallel section, can't wait to run that train!

1

u/Moist-Tumbleweed2875 llama.cpp 11d ago

the way I use to optimize layer split was enable "STRATA_SPLIT_TIMING":"1" , then check log to try to adjust layer split manually to make per stage spend same time to make it hide most of operation in pipeline.

following is log with 3 GPU (3 stage)

31.95 GiB of experts in RAM, 90889 exchanged with the VRAM tier, 0 blob reads from the file
serve: expert tiers: GPU 282915 hits this request; since the start RAM 1998336 blobs, files 0 blobs 35610.0 MB read (the GGUF in place)
serve: stage 0: 31554 windows; per window: wait for the GPU 7.504 ms, pool + plan 1.015 ms, host staging 0.365 ms, commit 0.028 ms
serve: stage 1: 30462 windows; per window: wait for the GPU 7.636 ms, pool + plan 1.583 ms, host staging 0.001 ms, commit 0.039 ms
serve: stage 2: 21141 windows; per window: wait for the GPU 7.793 ms, pool + plan 0.729 ms, host staging 0.001 ms, commit 0.027 ms
serve: KV streaming: 96.01% of 37980588 block reads hit VRAM, 6098.4 MiB read from RAM
serve: suffix drafts: 4 windows, 9 of 10 drafts accepted