Coder Social home page Coder Social logo

[Bug] fix steps check about llama2.go HOT 3 CLOSED

datastream avatar datastream commented on June 12, 2024 1
[Bug] fix steps check

from llama2.go.

Comments (3)

nikolaydubina avatar nikolaydubina commented on June 12, 2024

interesting. @datastream recommend submitting this issue/fix to llama2.c too

from llama2.go.

nikolaydubina avatar nikolaydubina commented on June 12, 2024

fixed. thanks @datastream 👍🏻

from llama2.go.

nikolaydubina avatar nikolaydubina commented on June 12, 2024

investigation notes

key_cache len: p->n_layers * p->seq_len * p->dim

if steps is too large
steps == seq_len 

at the end of main loop 
pos == steps - 1
(pos == seq_len - 1)

at the end of loop in transformer 
t == pos (thus, t == seq_len - 1)
float* k = s->key_cache + loff + t * dim + h * head_size;

l == num_layers-1
loff == l * p->seq_len * dim

h == num_heads - 1

then loop up to head size + head_size.

---

thus k  = (num_layers-1) * seq_len * dim + (seq_len-1) * dim + (num_heads-1) * head_size + (head_size - 1)
k = num_layers * seq_len * dim - seq_len * dim + seq_len * dim - dim + num_heads * head_size - head_size + head_size - 1
k = num_layers * seq_len * dim - dim + num_heads * head_size - 1
k = num_layers * seq_len * dim - dim + num_heads * dim / num_heads - 1
k = num_layers * seq_len * dim - 1

max_k index = num_layers * seq_len * dim - 1

dim = 768
num_heads = 12
head_size = dim  / num_heads

---

thus official run.c code is correct and does not breach array size.

from llama2.go.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.