Browse Source

- Fixed example

- Growing more than double, if necessary
tags/v0.10.0
Martin Evans 1 year ago
parent
commit
9fe878ae1f
2 changed files with 5 additions and 5 deletions
  1. +1
    -1
      LLama.Examples/Examples/BatchedDecoding.cs
  2. +4
    -4
      LLama/Native/LLamaBatch.cs

+ 1
- 1
LLama.Examples/Examples/BatchedDecoding.cs View File

@@ -52,7 +52,7 @@ public class BatchedDecoding
return; return;
} }


var batch = new LLamaBatch(1);
var batch = new LLamaBatch();


// evaluate the initial prompt // evaluate the initial prompt
for (var i = 0; i < prompt_tokens.Length; i++) for (var i = 0; i < prompt_tokens.Length; i++)


+ 4
- 4
LLama/Native/LLamaBatch.cs View File

@@ -38,7 +38,7 @@ public class LLamaBatch
{ {
// These can both be grown later, start off with reasonable numbers. // These can both be grown later, start off with reasonable numbers.
const int n_tokens = 128; const int n_tokens = 128;
const int n_seq_max = 4;
const int n_seq_max = 1;


MaxSequences = n_seq_max; MaxSequences = n_seq_max;
TokenCapacity = n_tokens; TokenCapacity = n_tokens;
@@ -77,9 +77,9 @@ public class LLamaBatch
} }
} }


private void GrowMaxSequences()
private void GrowMaxSequences(int atLeast)
{ {
var n_seq = MaxSequences * 2;
var n_seq = Math.Max(MaxSequences * 2, atLeast);
MaxSequences = n_seq; MaxSequences = n_seq;


for (var i = 0; i < _sequenceIds.Length; i++) for (var i = 0; i < _sequenceIds.Length; i++)
@@ -130,7 +130,7 @@ public class LLamaBatch
if (TokenCount == TokenCapacity) if (TokenCount == TokenCapacity)
GrowTokenCapacity(); GrowTokenCapacity();
if (sequences.Length > MaxSequences) if (sequences.Length > MaxSequences)
GrowMaxSequences();
GrowMaxSequences(sequences.Length);


_tokens[TokenCount] = token; _tokens[TokenCount] = token;
_positions[TokenCount] = pos; _positions[TokenCount] = pos;


Loading…
Cancel
Save