You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

llama.statefulexecutorbase.md 5.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. # StatefulExecutorBase
  2. Namespace: LLama
  3. The base class for stateful LLama executors.
  4. ```csharp
  5. public abstract class StatefulExecutorBase : LLama.Abstractions.ILLamaExecutor
  6. ```
  7. Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [StatefulExecutorBase](./llama.statefulexecutorbase.md)<br>
  8. Implements [ILLamaExecutor](./llama.abstractions.illamaexecutor.md)
  9. ## Properties
  10. ### **Model**
  11. The mode used by the executor.
  12. ```csharp
  13. public LLamaModel Model { get; }
  14. ```
  15. #### Property Value
  16. [LLamaModel](./llama.llamamodel.md)<br>
  17. ## Methods
  18. ### **WithSessionFile(String)**
  19. This API is currently not verified.
  20. ```csharp
  21. public StatefulExecutorBase WithSessionFile(string filename)
  22. ```
  23. #### Parameters
  24. `filename` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  25. #### Returns
  26. [StatefulExecutorBase](./llama.statefulexecutorbase.md)<br>
  27. #### Exceptions
  28. [ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception)<br>
  29. [RuntimeError](./llama.exceptions.runtimeerror.md)<br>
  30. ### **SaveSessionFile(String)**
  31. This API has not been verified currently.
  32. ```csharp
  33. public void SaveSessionFile(string filename)
  34. ```
  35. #### Parameters
  36. `filename` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  37. ### **HandleRunOutOfContext(Int32)**
  38. After running out of the context, take some tokens from the original prompt and recompute the logits in batches.
  39. ```csharp
  40. protected void HandleRunOutOfContext(int tokensToKeep)
  41. ```
  42. #### Parameters
  43. `tokensToKeep` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  44. ### **TryReuseMathingPrefix()**
  45. Try to reuse the matching prefix from the session file.
  46. ```csharp
  47. protected void TryReuseMathingPrefix()
  48. ```
  49. ### **GetLoopCondition(InferStateArgs)**
  50. Decide whether to continue the loop.
  51. ```csharp
  52. protected abstract bool GetLoopCondition(InferStateArgs args)
  53. ```
  54. #### Parameters
  55. `args` [InferStateArgs](./llama.statefulexecutorbase.inferstateargs.md)<br>
  56. #### Returns
  57. [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  58. ### **PreprocessInputs(String, InferStateArgs)**
  59. Preprocess the inputs before the inference.
  60. ```csharp
  61. protected abstract void PreprocessInputs(string text, InferStateArgs args)
  62. ```
  63. #### Parameters
  64. `text` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  65. `args` [InferStateArgs](./llama.statefulexecutorbase.inferstateargs.md)<br>
  66. ### **PostProcess(InferenceParams, InferStateArgs, IEnumerable`1&)**
  67. Do some post processing after the inference.
  68. ```csharp
  69. protected abstract bool PostProcess(InferenceParams inferenceParams, InferStateArgs args, IEnumerable`1& extraOutputs)
  70. ```
  71. #### Parameters
  72. `inferenceParams` [InferenceParams](./llama.common.inferenceparams.md)<br>
  73. `args` [InferStateArgs](./llama.statefulexecutorbase.inferstateargs.md)<br>
  74. `extraOutputs` [IEnumerable`1&](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1&)<br>
  75. #### Returns
  76. [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  77. ### **InferInternal(InferenceParams, InferStateArgs)**
  78. The core inference logic.
  79. ```csharp
  80. protected abstract void InferInternal(InferenceParams inferenceParams, InferStateArgs args)
  81. ```
  82. #### Parameters
  83. `inferenceParams` [InferenceParams](./llama.common.inferenceparams.md)<br>
  84. `args` [InferStateArgs](./llama.statefulexecutorbase.inferstateargs.md)<br>
  85. ### **SaveState(String)**
  86. Save the current state to a file.
  87. ```csharp
  88. public abstract void SaveState(string filename)
  89. ```
  90. #### Parameters
  91. `filename` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  92. ### **GetStateData()**
  93. Get the current state data.
  94. ```csharp
  95. public abstract ExecutorBaseState GetStateData()
  96. ```
  97. #### Returns
  98. [ExecutorBaseState](./llama.statefulexecutorbase.executorbasestate.md)<br>
  99. ### **LoadState(ExecutorBaseState)**
  100. Load the state from data.
  101. ```csharp
  102. public abstract void LoadState(ExecutorBaseState data)
  103. ```
  104. #### Parameters
  105. `data` [ExecutorBaseState](./llama.statefulexecutorbase.executorbasestate.md)<br>
  106. ### **LoadState(String)**
  107. Load the state from a file.
  108. ```csharp
  109. public abstract void LoadState(string filename)
  110. ```
  111. #### Parameters
  112. `filename` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  113. ### **Infer(String, InferenceParams, CancellationToken)**
  114. Execute the inference.
  115. ```csharp
  116. public IEnumerable<string> Infer(string text, InferenceParams inferenceParams, CancellationToken cancellationToken)
  117. ```
  118. #### Parameters
  119. `text` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  120. `inferenceParams` [InferenceParams](./llama.common.inferenceparams.md)<br>
  121. `cancellationToken` [CancellationToken](https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken)<br>
  122. #### Returns
  123. [IEnumerable&lt;String&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>
  124. ### **InferAsync(String, InferenceParams, CancellationToken)**
  125. Execute the inference asynchronously.
  126. ```csharp
  127. public IAsyncEnumerable<string> InferAsync(string text, InferenceParams inferenceParams, CancellationToken cancellationToken)
  128. ```
  129. #### Parameters
  130. `text` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  131. `inferenceParams` [InferenceParams](./llama.common.inferenceparams.md)<br>
  132. `cancellationToken` [CancellationToken](https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken)<br>
  133. #### Returns
  134. [IAsyncEnumerable&lt;String&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1)<br>

C#/.NET上易用的LLM高性能推理框架,支持LLaMA和LLaVA系列模型。