mirror of https://github.com/maderix/ANE.git
fix(HIGH-01): add embed_backward clamp and cleanup on early-exit
- stories_cpu_ops.h: apply same VOCAB clamp in embed_backward() to prevent OOB write / heap corruption (mirrors embed_lookup fix) - train_large.m: munmap+close before early-exit to avoid FD/mmap leak
This commit is contained in:
parent
168754cb8e
commit
ef1bb7dec1
|
|
@ -123,6 +123,7 @@ static void embed_lookup(float *x, const float *embed, const uint16_t *tokens, i
|
|||
static void embed_backward(float *d_embed, const float *dx, const uint16_t *tokens, int dim, int seq) {
|
||||
for (int t = 0; t < seq; t++) {
|
||||
int tok = tokens[t];
|
||||
if (tok >= VOCAB) { tok = 0; } // HIGH-01: clamp invalid token -> position 0
|
||||
for (int d = 0; d < dim; d++) {
|
||||
d_embed[tok*dim + d] += dx[d*seq + t];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -298,6 +298,8 @@ int main(int argc, char *argv[]) {
|
|||
size_t n_tokens = data_len / 2;
|
||||
if (n_tokens < (size_t)SEQ + 1) {
|
||||
fprintf(stderr, "Token file too small: %zu tokens, need >%d\n", n_tokens, SEQ + 1);
|
||||
munmap(token_data, data_len);
|
||||
close(data_fd);
|
||||
return 1;
|
||||
}
|
||||
printf("Token data: %zu tokens (%.1f MB)\n", n_tokens, data_len/1e6);
|
||||
|
|
|
|||
Loading…
Reference in New Issue