Skip to content

Commit 4772eb7

Browse files
committed
Made randomization of default Seed initialization be thread safe
1 parent ba9a518 commit 4772eb7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

LLama/Sampling/DefaultSamplingPipeline.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public sealed class DefaultSamplingPipeline
2020
/// </summary>
2121
public float RepeatPenalty { get; init; } = 1;
2222

23-
2423
/// <summary>
2524
/// Frequency penalty as described by OpenAI: https://platform.openai.com/docs/api-reference/chat/create<br />
2625
/// Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text
@@ -156,7 +155,16 @@ public float PresencePenalty
156155
/// <summary>
157156
/// Seed to use for random sampling
158157
/// </summary>
159-
public uint Seed { get; set; } = (uint) new Random().Next(0, int.MaxValue);
158+
public uint Seed { get; set; } = GetRandomSeed();
159+
160+
161+
private static Random RandomSeedGenerator = new();
162+
private static uint GetRandomSeed()
163+
{
164+
lock (RandomSeedGenerator)
165+
return (uint) RandomSeedGenerator.Next(0, int.MaxValue) + (uint) RandomSeedGenerator.Next(0, int.MaxValue);
166+
}
167+
160168

161169
/// <inheritdoc />
162170
protected override SafeLLamaSamplerChainHandle CreateChain(SafeLLamaContextHandle context)

0 commit comments

Comments
 (0)