浏览代码

`BatchedExecutor.Create()` method (#613)

Replaced `BatchedExecutor.Prompt(string)` method with `BatchedExecutor.Create()` method. This improves the API in two ways:
 - A conversation can be created, without immediately prompting it
 - Other prompting overloads (e.g. prompt with token list) can be used without duplicating all the overloads onto `BatchedExecutor`

Added `BatchSize` property to `LLamaContext`
tags/0.11.0
Martin Evans GitHub 1年前
父节点
当前提交
ad682fbebd
找不到此签名对应的密钥 GPG 密钥 ID: B5690EEEBB952194
共有 5 个文件被更改,包括 27 次插入5 次删除
  1. +2
    -1
      LLama.Examples/Examples/BatchedExecutorFork.cs
  2. +4
    -2
      LLama.Examples/Examples/BatchedExecutorGuidance.cs
  3. +2
    -1
      LLama.Examples/Examples/BatchedExecutorRewind.cs
  4. +14
    -1
      LLama/Batched/BatchedExecutor.cs
  5. +5
    -0
      LLama/LLamaContext.cs

+ 2
- 1
LLama.Examples/Examples/BatchedExecutorFork.cs 查看文件

@@ -31,7 +31,8 @@ public class BatchedExecutorFork
Console.WriteLine($"Created executor with model: {name}");

// Evaluate the initial prompt to create one conversation
using var start = executor.Prompt(prompt);
using var start = executor.Create();
start.Prompt(prompt);
await executor.Infer();

// Create the root node of the tree


+ 4
- 2
LLama.Examples/Examples/BatchedExecutorGuidance.cs 查看文件

@@ -33,8 +33,10 @@ public class BatchedExecutorGuidance
Console.WriteLine($"Created executor with model: {name}");

// Load the two prompts into two conversations
using var guided = executor.Prompt(positivePrompt);
using var guidance = executor.Prompt(negativePrompt);
using var guided = executor.Create();
guided.Prompt(positivePrompt);
using var guidance = executor.Create();
guidance.Prompt(negativePrompt);

// Run inference to evaluate prompts
await AnsiConsole


+ 2
- 1
LLama.Examples/Examples/BatchedExecutorRewind.cs 查看文件

@@ -32,7 +32,8 @@ public class BatchedExecutorRewind
Console.WriteLine($"Created executor with model: {name}");

// Evaluate the initial prompt to create one conversation
using var conversation = executor.Prompt(prompt);
using var conversation = executor.Create();
conversation.Prompt(prompt);
// Create the start node wrapping the conversation
var node = new Node(executor.Context);


+ 14
- 1
LLama/Batched/BatchedExecutor.cs 查看文件

@@ -68,17 +68,30 @@ public sealed class BatchedExecutor
/// </summary>
/// <param name="prompt"></param>
/// <returns></returns>
[Obsolete("Use BatchedExecutor.Create instead")]
public Conversation Prompt(string prompt)
{
if (IsDisposed)
throw new ObjectDisposedException(nameof(BatchedExecutor));

var conversation = new Conversation(this, GetNextSequenceId(), 0);
var conversation = Create();
conversation.Prompt(prompt);

return conversation;
}

/// <summary>
/// Start a new <see cref="Conversation"/>
/// </summary>
/// <returns></returns>
public Conversation Create()
{
if (IsDisposed)
throw new ObjectDisposedException(nameof(BatchedExecutor));

return new Conversation(this, GetNextSequenceId(), 0);
}

/// <summary>
/// Run inference for all conversations in the batch which have pending tokens.
///


+ 5
- 0
LLama/LLamaContext.cs 查看文件

@@ -85,6 +85,11 @@ namespace LLama
}
}

/// <summary>
/// Get the maximum batch size for this context
/// </summary>
public uint BatchSize => NativeHandle.BatchSize;

/// <summary>
/// Create a new LLamaContext for the given LLamaWeights
/// </summary>


正在加载...
取消
保存