Skip to content

Commit

Permalink
bos-update
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaydubina committed Aug 7, 2023
1 parent d390083 commit 4a8479b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func main() {

// the current position we are in
timeStart := time.Now()
var token int = 1 // 1 = BOS token in llama-2 sentencepiece
out.Write([]byte("<s>\n")) // explicit print initial BOS token for stylistic symmetry reasons
for pos := 0; pos < steps; pos++ {
var token int = 1 // 1 = BOS token in llama-2 sentencepiece
var pos = 0
for pos < steps {
// forward the transformer to get logits for the next token
llama2.Transformer(token, pos, config, runState, w)

Expand All @@ -92,8 +92,14 @@ func main() {
next = nn.Sample(runState.Logits)
}
}
pos++

// following BOS token (1), sentencepiece decoder strips any leading whitespace
// data-dependent terminating condition: the BOS (1) token delimits sequences
if next == 1 {
break
}

// following BOS (1) token, sentencepiece decoder strips any leading whitespace
var tokenStr string
if token == 1 && vocab.Words[next][0] == ' ' {
tokenStr = vocab.Words[next][1:]
Expand All @@ -107,5 +113,5 @@ func main() {
}
out.Write([]byte("\n"))

log.Printf("achieved tok/s: %f\n", float64(steps)/time.Since(timeStart).Seconds())
log.Printf("achieved tok/s: %f\n", float64(pos-1)/time.Since(timeStart).Seconds())
}

0 comments on commit 4a8479b

Please sign in to comment.