# StatefulExecutorBase
Namespace: LLama
The base class for stateful LLama executors.
```csharp
public abstract class StatefulExecutorBase : LLama.Abstractions.ILLamaExecutor
```
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [StatefulExecutorBase](./llama.statefulexecutorbase.md)
Implements [ILLamaExecutor](./llama.abstractions.illamaexecutor.md)
## Properties
### **Model**
The mode used by the executor.
```csharp
public LLamaModel Model { get; }
```
#### Property Value
[LLamaModel](./llama.llamamodel.md)
## Methods
### **WithSessionFile(String)**
This API is currently not verified.
```csharp
public StatefulExecutorBase WithSessionFile(string filename)
```
#### Parameters
`filename` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)
#### Returns
[StatefulExecutorBase](./llama.statefulexecutorbase.md)
#### Exceptions
[ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception)
[RuntimeError](./llama.exceptions.runtimeerror.md)
### **SaveSessionFile(String)**
This API has not been verified currently.
```csharp
public void SaveSessionFile(string filename)
```
#### Parameters
`filename` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)
### **HandleRunOutOfContext(Int32)**
After running out of the context, take some tokens from the original prompt and recompute the logits in batches.
```csharp
protected void HandleRunOutOfContext(int tokensToKeep)
```
#### Parameters
`tokensToKeep` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)
### **TryReuseMathingPrefix()**
Try to reuse the matching prefix from the session file.
```csharp
protected void TryReuseMathingPrefix()
```
### **GetLoopCondition(InferStateArgs)**
Decide whether to continue the loop.
```csharp
protected abstract bool GetLoopCondition(InferStateArgs args)
```
#### Parameters
`args` [InferStateArgs](./llama.statefulexecutorbase.inferstateargs.md)
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)
### **PreprocessInputs(String, InferStateArgs)**
Preprocess the inputs before the inference.
```csharp
protected abstract void PreprocessInputs(string text, InferStateArgs args)
```
#### Parameters
`text` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)
`args` [InferStateArgs](./llama.statefulexecutorbase.inferstateargs.md)
### **PostProcess(InferenceParams, InferStateArgs, IEnumerable`1&)**
Do some post processing after the inference.
```csharp
protected abstract bool PostProcess(InferenceParams inferenceParams, InferStateArgs args, IEnumerable`1& extraOutputs)
```
#### Parameters
`inferenceParams` [InferenceParams](./llama.common.inferenceparams.md)
`args` [InferStateArgs](./llama.statefulexecutorbase.inferstateargs.md)
`extraOutputs` [IEnumerable`1&](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1&)
#### Returns
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)
### **InferInternal(InferenceParams, InferStateArgs)**
The core inference logic.
```csharp
protected abstract void InferInternal(InferenceParams inferenceParams, InferStateArgs args)
```
#### Parameters
`inferenceParams` [InferenceParams](./llama.common.inferenceparams.md)
`args` [InferStateArgs](./llama.statefulexecutorbase.inferstateargs.md)
### **SaveState(String)**
Save the current state to a file.
```csharp
public abstract void SaveState(string filename)
```
#### Parameters
`filename` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)
### **GetStateData()**
Get the current state data.
```csharp
public abstract ExecutorBaseState GetStateData()
```
#### Returns
[ExecutorBaseState](./llama.statefulexecutorbase.executorbasestate.md)
### **LoadState(ExecutorBaseState)**
Load the state from data.
```csharp
public abstract void LoadState(ExecutorBaseState data)
```
#### Parameters
`data` [ExecutorBaseState](./llama.statefulexecutorbase.executorbasestate.md)
### **LoadState(String)**
Load the state from a file.
```csharp
public abstract void LoadState(string filename)
```
#### Parameters
`filename` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)
### **Infer(String, InferenceParams, CancellationToken)**
Execute the inference.
```csharp
public IEnumerable Infer(string text, InferenceParams inferenceParams, CancellationToken cancellationToken)
```
#### Parameters
`text` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)
`inferenceParams` [InferenceParams](./llama.common.inferenceparams.md)
`cancellationToken` [CancellationToken](https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken)
#### Returns
[IEnumerable<String>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)
### **InferAsync(String, InferenceParams, CancellationToken)**
Execute the inference asynchronously.
```csharp
public IAsyncEnumerable InferAsync(string text, InferenceParams inferenceParams, CancellationToken cancellationToken)
```
#### Parameters
`text` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)
`inferenceParams` [InferenceParams](./llama.common.inferenceparams.md)
`cancellationToken` [CancellationToken](https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken)
#### Returns
[IAsyncEnumerable<String>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1)