Skip to content

Expose DecodeSpecialTokens through IInferenceParams for StatelessExecutor #1203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions LLama.Web/Common/InferenceOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ public class InferenceOptions

/// <inheritdoc />
public ISamplingPipeline SamplingPipeline { get; set; } = new DefaultSamplingPipeline();

/// <inheritdoc />
public bool DecodeSpecialTokens { get; set; }
}
}
8 changes: 8 additions & 0 deletions LLama/Abstractions/IInferenceParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@ public interface IInferenceParams
/// Set a custom sampling pipeline to use.
/// </summary>
ISamplingPipeline SamplingPipeline { get; set; }

/// <summary>
/// If true, special characters will be converted to text. If false they will be invisible.
/// </summary>
/// <remark>
/// Controls the behavior of decoders like <see cref="StreamingTokenDecoder" />
/// </remark>
public bool DecodeSpecialTokens { get; set; }
}
}
3 changes: 3 additions & 0 deletions LLama/Common/InferenceParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public record InferenceParams

/// <inheritdoc />
public ISamplingPipeline SamplingPipeline { get; set; } = new DefaultSamplingPipeline();

/// <inheritdoc />
public bool DecodeSpecialTokens { get; set; }
}

/// <summary>
Expand Down
5 changes: 4 additions & 1 deletion LLama/LLamaStatelessExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ public async IAsyncEnumerable<string> InferAsync(string prompt, IInferenceParams
throw new ArgumentOutOfRangeException(nameof(inferenceParams), $"TokensKeep ({inferenceParams.TokensKeep}) cannot be larger than ContextSize ({Context.ContextSize})");

// Create decoders for the token stream
var decoder = new StreamingTokenDecoder(Context);
var decoder = new StreamingTokenDecoder(Context)
{
DecodeSpecialTokens = inferenceParams.DecodeSpecialTokens,
};
var antiprocessor = new AntipromptProcessor(inferenceParams.AntiPrompts);

if (ApplyTemplate)
Expand Down
Loading