Repository navigation
metal : key the fa-vec tuned table by family instead of SKU - #29075
Conversation
nikwen
left a comment
There was a problem hiding this comment.
Thank you so much for working on this!
The fusion tests failed in CI (not sure if related):
0.03.409.038 I summary: 151 ok, 1 failed
0.03.409.038 W main: if the fusion counts are expected to change, run with --record to update the baseline:
./bin/test-llama-archs -o build-ci-models
A few comments inline. The rest looks good to me. 👍
| { { GGML_METAL_DEVICE_M5_PRO, GGML_TYPE_Q8_0, 192, 192, 3, 2 }, { 1, 4 } }, | ||
| { { GGML_METAL_DEVICE_M5_PRO, GGML_TYPE_Q8_0, 192, 128, -1, 0 }, { 1, 4 } }, | ||
| { { GGML_METAL_DEVICE_M5_PRO, GGML_TYPE_Q8_0, 192, 128, -1, 1 }, { 2, 4 } }, | ||
| { { GGML_METAL_DEVICE_M5_PRO, GGML_TYPE_Q |
There was a problem hiding this comment.
It would be great to have:
- documentation on how to arrive at these unified values if we have the sweep results for each device
- maybe a script for it (I doubt you arrived at them by hand :) )
- a record of all historical sweep results and sweep logs somewhere (new file/directory in the repo?)
That would:
- ensure that the method is documented somewhere and that we can apply it in the future when we need to tune new devices (M6 family 👀)
- allow us to slightly improve the existing values by incorporating more devices into the mix (e.g., M5 and M5 Pro are missing from family 10 as far as I can tell)
- allow us to update the tuning results if it becomes necessary in the future
- allow people to reproduce the results for themselves
There was a problem hiding this comment.
You're right that we should have a reproducible workflow for this, especially for tuning new devices in the future. I'm planning to add the functionality for converting offline-collected sweep logs into table rows, as well as evaluating the performance of a newly generated table, to ggml-metal-tuning.
I'd prefer to keep this in ggml-metal-tuning rather than introduce a separate Python script (I did use a local Python script to generate these values), so the tuning logic stays in one place and doesn't drift between multiple implementations.
There was a problem hiding this comment.
Awesome, thank you! Doing that in a separate PR makes sense to me.
| @@ -66,3922 +66,1053 @@ fa_vec_cfg_t fa_vec_baseline_cfg(int dk, int dv) { | |||
| } | |||
|
|
|||
| // Generated by `ggml-metal-tuning fa-vec`; do not hand-edit. | |||
There was a problem hiding this comment.
Is this still true? Or are they derived from the output of that command by running another script?
There was a problem hiding this comment.
This is no longer accurate. I'll update the comment once the tooling is in place to reflect the actual generation workflow.
452fed2 to
c05b880
Compare
|
@nikwen Thanks for the review! The CI failure should be unrelated to this PR. I've rebased onto the latest master, so let's see if it goes away after the rebase. |
nikwen
left a comment
There was a problem hiding this comment.
Thanks for the updates and for working on the feature! :)
|
@forforever73 Shall we merge this? |
|
It should be good to merge, but we leave it to the author to decide. |
|
@nikwen Yes, please. I'll address the remaining items in follow-up pr. |
…#29075) * key the fa-vec tuned table by family instead of SKU * fall back to baseline for untuned fa-vec gpu families
Overview
taking the per-family direction that came out of discussion #27668.
fa_vec_tuned_tableis rekeyed fromdevice_idtogpu_family: 3884 rows across 19 SKUs become 1033 rows across 4 Apple GPU families.fa_vec_pickloses itsdevice_idargument and its representative-SKU retry, so the lookup is one level instead of two. The tool still emits per-SKU rows.End-to-end on M4 Max
Nothing regresses: the lowest cell is 0.999×. The small gain is consistent and reproducible, but it does not come from the kernel — it comes from cheaper lookup.
find_cfgperforms a linear table scan. For this workload, M4 Max often misses the exact bucket and falls back to the default config; the old path can scan the full table up to four times, including redundant retries through the family representative SKU (which is M4 Max itself for family 9).Keying by family removes those redundant scans and searches a table 3.8× smaller, reducing lookup cost from 2149 ns to 282 ns per call. This also explains the small gains in cells where the selected config is unchanged.
None of this says the pooled rows pick faster kernels. In-sample they are 98.5% of per-device tuning at the attention level — marginally slower — which end to end is below what this test can resolve.
Requirements