mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-09-19 17:24:57 +02:00
sampling : remove backend-dist option (wip)
This commit removes the `--backend-dist` option and instead uses the
configured --samplers chain to determine which samplers run on the
backend.
Backend sampling is still enabled using With `--backend_sampling`, and
the sampler chain, either explictly specified using `--samplers` or the
default, is automatically analyzed to determine which samplers can run
on the backend. The system finds the longest contiguous chain of
backend supported samplers from the start of the sampler sequence.
For example:
* If the chain is `top-k -> temperature -> top-p`, and both `top-k` and
`temperature` are backend-supported but `top-p` is not, then `top-k`
and `temperature` will run on the backend, while `top-p` and
subsequent samplers run on the CPU.
* If all configured samplers are supported, the final distribution
sampling will also happen on the backend, transferring only the
sampled token IDs back to the host.
* If the sampler chain starts with an unsupported sampler (e.g.,
`penalties`), all sampling runs on the CPU. Note that this is
currently the case with the default sampler so to use backend sampling
it is required to specify a sampler chain. See below for an example.
The following shows how llama-cli can be run with backend sampling:
```console
$ llama-cli -m models/Qwen2.5-VL-3B-Instruct-Q8_0.gguf \
--prompt 'What is the capital of Sweden?' \
-n 20 \
-no-cnv \
--verbose-prompt \
-ngl 40 \
--backend-sampling \
--samplers 'top_k;temperature'
```
In this case the all sampling will happen on the backend since both
`top_k` and `temperature` are supported backend samplers.
To enable a partial backend sampling (hybrid sampling), for example
running `top_k` and `temperature` on the backend and `typ_p` on the CPU
the following sampler chain could be specified:
```console
$ llama-cli -m models/Qwen2.5-VL-3B-Instruct-Q8_0.gguf \
--prompt 'What is the capital of Sweden?' \
-n 20 \
-no-cnv \
--verbose-prompt \
-ngl 40 \
--backend-sampling \
--samplers 'top_k;temperature;top_p'
```
If this looks good then I'll follow up with updates the llama-cli and
llama-server documentation to reflect these changes.
This commit is contained in:
+30
-17
@@ -45,25 +45,38 @@ llama_print_timings: total time = 4156.04 ms
|
||||
|
||||
### Using backend samplers
|
||||
It is possible to run this example using backend samplers so that sampling is
|
||||
performed on the backend device, like a GPU.
|
||||
performed on a backend device, like a GPU.
|
||||
```bash
|
||||
./llama-batched \
|
||||
-m models/Qwen2.5-VL-3B-Instruct-Q8_0.gguf -p "Hello my name is" \
|
||||
-np 4 -kvu \
|
||||
--backend_sampling --top-k 80 --backend_dist
|
||||
-np 4 \
|
||||
-kvu \
|
||||
--backend_sampling \
|
||||
--samplers 'top_k;temperature' \
|
||||
--top-k 80
|
||||
```
|
||||
The `--verbose` flag can be added to see more detailed output and also show
|
||||
that the backend samplers are being used. The above example will perform distribution
|
||||
sampling on the backend device and only transfer the sampled token ids back to the host.
|
||||
The samplers specified with `--samplers` must be supported by the backend and
|
||||
this is why we are explicitly specifying only `top_k` and `temperature` here as
|
||||
at the time of writing these are supported.
|
||||
|
||||
It is also possible to perform partial sampling on the backend, and then allow CPU samplers
|
||||
to process those results further. This is sometimes referred to as hybrid sampling.
|
||||
For an example of this we can remove `--backend_dist` from the above command:
|
||||
```bash
|
||||
./llama-batched \
|
||||
-m models/Qwen2.5-VL-3B-Instruct-Q8_0.gguf -p "Hello my name is" \
|
||||
-np 4 -kvu \
|
||||
--backend_sampling --top-k 80 -v
|
||||
```
|
||||
This will perform the top-k filtering on the backend device, and then transfer the filtered logits
|
||||
back to the host for sampling.
|
||||
The `--verbose` flag can be added to see more detailed output and also show
|
||||
that the backend samplers are being used.
|
||||
|
||||
With `--backend_sampling` enabled, the sampler chain is automatically analyzed
|
||||
to determine which samplers can run on the backend. The system finds the longest
|
||||
contiguous chain of backend-supported samplers from the start of the sampler
|
||||
sequence. For example:
|
||||
* If the chain is `top-k -> temperature -> top-p`, and both `top-k` and
|
||||
`temperature` are backend-supported but `top-p` is not, then `top-k` and
|
||||
`temperature` will run on the backend, while `top-p` and subsequent samplers
|
||||
run on the CPU.
|
||||
* If all configured samplers are supported, the final distribution sampling will
|
||||
also happen on the backend, transferring only the sampled token IDs back to the
|
||||
host.
|
||||
* If the sampler chain starts with an unsupported sampler (e.g., `penalties`),
|
||||
all sampling runs on the CPU.
|
||||
|
||||
**Note:** The default sampler chain includes `penalties` as the first sampler,
|
||||
which is not backend-supported yet. To use backend sampling, you must explicitly
|
||||
configure a sampler chain that starts with backend-supported samplers using
|
||||
`--samplers` like shown above.
|
||||
|
||||
Reference in New Issue
Block a user