Parametros seguem o bloco do editor (origin), nao a instancia remontada
O editor esquece o cache das arvores quando o usuario edita algo e monta outra instancia para o mesmo bloco da tela. Como os pesos da tensor eram achados pela instancia, cada remontagem comecava com pesos novos: no treino da GAN a perda voltava ao formato do inicio de tempos em tempos. Cada bloco da tela ganha um uid e as instancias levam esse uid em TinyBlocks_Block.origin. tt_param acha o parametro pela origem (sem origem, pela propria instancia) e a instancia nova herda os pesos; a velha, ao morrer, nao leva os da nova. As medias moveis do batch norm passam a ser parametros sem gradiente, para irem junto no "salve os parametros". Testes: test-tensor ganha a heranca pela origem; os donos de mentira dos testes viram blocos zerados (o param_key le owner->origin).
This commit is contained in:
1 parent
422c3fb6cb
commit
a26d329521
12 files changed
+68
-22
No files matched your search
@@ -137,16 +137,16 @@ static void eval_batchnorm(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
if (x->nd < 2) A->set_error("batch norm precisa de [lote, canais, ...]");
|
||||
else {
|
||||
int C = x->shape[1];
|
||||
Layer* L = self->userdata;
|
||||
if (!L->buf[0] || (int)L->buf[0]->n != C) { /* medias moveis (nao treinam) */
|
||||
A->release(L->buf[0]); A->release(L->buf[1]);
|
||||
L->buf[0] = A->alloc(1, &C);
|
||||
L->buf[1] = A->alloc(1, &C);
|
||||
for (int i = 0; L->buf[1] && i < C; i++) L->buf[1]->d[i] = 1;
|
||||
}
|
||||
TbTensor* g = P(self, 0, 1, &C, TB_INIT_ONES, 1);
|
||||
TbTensor* b = P(self, 1, 1, &C, TB_INIT_ZEROS, 0);
|
||||
if (g && b && L->buf[0] && L->buf[1]) r = ai_batchnorm(x, g, b, L->buf[0], L->buf[1], g_ai_train, 0.1f);
|
||||
/* medias moveis: parametros sem gradiente (os otimizadores pulam),
|
||||
para irem junto no "salve os parametros" e sobreviverem quando o
|
||||
editor remonta o bloco */
|
||||
TbTensor* mean = P(self, 2, 1, &C, TB_INIT_ZEROS, 0);
|
||||
TbTensor* var = P(self, 3, 1, &C, TB_INIT_ONES, 1);
|
||||
if (mean) mean->req = false;
|
||||
if (var) var->req = false;
|
||||
if (g && b && mean && var) r = ai_batchnorm(x, g, b, mean, var, g_ai_train, 0.1f);
|
||||
}
|
||||
rel(&x, 1); done(self, rt, r);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user