0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

ircd::gpt: Resolve behavior of opts.limit: 0=analysis, -n=unlimited, n=limited.

This commit is contained in:
Jason Volk 2022-10-09 01:00:40 +00:00
parent 1f57c224c6
commit c1168fcc30
2 changed files with 33 additions and 27 deletions

View file

@ -755,13 +755,11 @@ ircd::gpt::samp::samp(gpt::step &step)
} }
,count ,count
{ {
opts.limit > 0?
tokens - opts.limit:
opts.limit < 0? opts.limit < 0?
std::abs(opts.limit): std::min(std::abs(opts.limit), int(tokens)):
!ctrl.count? opts.limit > 0?
tokens: tokens:
1 1U
} }
{ {
desc.cached = 0; desc.cached = 0;

View file

@ -888,10 +888,9 @@ ircd_gpt_lm_result(__local struct ircd_gpt_ctrl *const ctrl,
// Update the token context. // Update the token context.
if(ctrl->count == ctrl->tokens) if(ctrl->count == ctrl->tokens)
{ ctrl->token[ctrl->tokens++] = ctrl->select.logit.token;
ctrl->token[ctrl->count] = ctrl->select.logit.token; else
ctrl->tokens++; ctrl->accept = -2;
}
ctrl->miss += !hit; ctrl->miss += !hit;
ctrl->hit += hit; ctrl->hit += hit;
@ -1074,34 +1073,43 @@ ircd_gpt_accept(__local struct ircd_gpt_ctrl *const ctrl,
__constant const struct ircd_gpt_opts *const opts) __constant const struct ircd_gpt_opts *const opts)
{ {
const bool const bool
unlimited = opts->limit < 0; unlimited = opts->limit < 0,
unprocessed = ctrl->accept == -2,
acceptable = ctrl->accept < 0 && !unprocessed;
const uint const uint
batch_size = opts->batch_size, batch_size = opts->batch_size,
samps = opts->training_steps + opts->validation_steps + opts->testing_steps, samps = opts->training_steps + opts->validation_steps + opts->testing_steps,
steps = samps / batch_size, steps = samps / batch_size,
limit_ = opts->limit, unproc = ctrl->tokens - ctrl->count,
unproc = ctrl->tokens - ctrl->count; limit = opts->limit;
const int const int
limit = min(limit_?: unproc, opts->context_tokens), cycle_remain = opts->context_tokens - (ctrl->clk.cycle + 1), // cycle not yet incr
cycle_remain = limit - (ctrl->clk.cycle + 1), // cycle not yet incr
token_remain = opts->context_tokens - ctrl->count, // but count already incr token_remain = opts->context_tokens - ctrl->count, // but count already incr
remain_ = min(cycle_remain, token_remain), remain = min(cycle_remain, token_remain);
accept_ = ircd_gpt_accept_check(ctrl, opts),
accept_abs = abs(accept_),
remain = accept_ < 0 && accept_abs < remain_? accept_abs: remain_,
_accept = accept_ >= 0? accept_: -remain;
const bool int
accepting = _accept >= 0, accept = ircd_gpt_accept_check(ctrl, opts),
dispatching = _accept < 0, dispatch = accept < 0? min(abs(accept), (uint)remain): 0;
limiting = remain <= 0;
const int if(opts->limit > 0 && ctrl->clk.cycle >= limit - 1)
accept_num = 4, {
accept = limiting? accept_num: _accept, accept = accept >= 0? accept: -1;
dispatch = accept >= 0? 0: remain; dispatch = 0;
}
if(opts->limit == 0 && unprocessed)
{
accept = -1;
dispatch = min((uint)remain, unproc);
}
if(opts->limit != 0 && !acceptable)
{
accept = -1;
dispatch = max(dispatch, 1);
}
ctrl->accept = accept; ctrl->accept = accept;
ctrl->dispatch = dispatch; ctrl->dispatch = dispatch;