amogaddy commited on
Commit
c6312bb
·
verified ·
1 Parent(s): 17b2436

Neuronal: modello su ZeroGPU

Browse files
Files changed (1) hide show
  1. src/brain.c +11 -2
src/brain.c CHANGED
@@ -1540,12 +1540,13 @@ int brain_layer_top(Brain *b, int layer, int k, int *idx, float *val, float *mea
1540
 
1541
  // ---- lato remoto (il processo sulla GPU) ----
1542
 
1543
- typedef struct { Brain *b; const BrainLink *l; SBuf s; } ServeCtx;
1544
 
1545
  static bool serve_token(void *ud, const char *piece, bool thought) {
1546
  ServeCtx *c = ud;
1547
  Brain *b = c->b;
1548
  SBuf *s = &c->s;
 
1549
  s->n = 0;
1550
  uint8_t th = thought;
1551
  uint16_t pl = (uint16_t)strlen(piece);
@@ -1569,7 +1570,11 @@ static bool serve_token(void *ud, const char *piece, bool thought) {
1569
  PUTN(s, b->areas[i].act, sizeof(float) * (size_t)an);
1570
  }
1571
  pthread_mutex_unlock(&b->mu);
1572
- if (!wire_send(c->l, 'T', s->p, s->n)) return false;
 
 
 
 
1573
  size_t n = 0;
1574
  uint8_t *x = c->l->recv(c->l->ud, &n, 0); // è arrivato l'ordine di fermarsi?
1575
  bool stop = x && n >= 1 && x[0] == 'X';
@@ -1636,7 +1641,11 @@ void brain_serve(Brain *b, const BrainLink *l, const char *mmproj_path) {
1636
  if (acap > (1u << 22)) acap = 1u << 22;
1637
  char *answer = malloc(acap);
1638
  int32_t res[2];
 
 
1639
  res[0] = local_chat(b, msgs, nm, &o, (fl & OPF_QUIET) ? NULL : serve_token, &c, answer, acap);
 
 
1640
  res[1] = (int32_t)b->last_stop;
1641
  uint32_t al = res[0] >= 0 ? (uint32_t)strlen(answer) + 1 : 0;
1642
  PUT(&out, res); PUT(&out, al);
 
1540
 
1541
  // ---- lato remoto (il processo sulla GPU) ----
1542
 
1543
+ typedef struct { Brain *b; const BrainLink *l; SBuf s; double t_digest, t_send; } ServeCtx;
1544
 
1545
  static bool serve_token(void *ud, const char *piece, bool thought) {
1546
  ServeCtx *c = ud;
1547
  Brain *b = c->b;
1548
  SBuf *s = &c->s;
1549
+ double t0 = mono_s();
1550
  s->n = 0;
1551
  uint8_t th = thought;
1552
  uint16_t pl = (uint16_t)strlen(piece);
 
1570
  PUTN(s, b->areas[i].act, sizeof(float) * (size_t)an);
1571
  }
1572
  pthread_mutex_unlock(&b->mu);
1573
+ double t1 = mono_s();
1574
+ bool sent = wire_send(c->l, 'T', s->p, s->n);
1575
+ c->t_digest += t1 - t0;
1576
+ c->t_send += mono_s() - t1;
1577
+ if (!sent) return false;
1578
  size_t n = 0;
1579
  uint8_t *x = c->l->recv(c->l->ud, &n, 0); // è arrivato l'ordine di fermarsi?
1580
  bool stop = x && n >= 1 && x[0] == 'X';
 
1641
  if (acap > (1u << 22)) acap = 1u << 22;
1642
  char *answer = malloc(acap);
1643
  int32_t res[2];
1644
+ double t0 = mono_s();
1645
+ c.t_digest = c.t_send = 0;
1646
  res[0] = local_chat(b, msgs, nm, &o, (fl & OPF_QUIET) ? NULL : serve_token, &c, answer, acap);
1647
+ fprintf(stderr, "generazione: %d token in %.2f s (riassunto dei neuroni %.2f s, invio %.2f s)" "
1648
+ ", res[0], mono_s() - t0, c.t_digest, c.t_send);
1649
  res[1] = (int32_t)b->last_stop;
1650
  uint32_t al = res[0] >= 0 ? (uint32_t)strlen(answer) + 1 : 0;
1651
  PUT(&out, res); PUT(&out, al);