SciSharp / LLamaSharp

A C#/.NET library to run LLM (🦙LLaMA/LLaVA) on your local device efficiently.
https://scisharp.github.io/LLamaSharp
MIT License
2.7k stars 349 forks source link

Custom Sampler Stages #961

Closed martindevans closed 3 weeks ago

martindevans commented 4 weeks ago

Added support for custom sampler stages, written entirely in safe C#. These stages can be added to a sampler pipeline just like any other. See the example in LLama.Examples\Examples\CustomSampler.cs for an example of a custom pipeline using a custom stage.

The internals here are fairly complex, because we need to keep some manually managed memory (so we can have persistent pointers to it) and also make sure the GC doesn't collect things. The overall flow is as follows: