Initialize optimizer research workspace with official baselines and history-free coverage

Vendor pinned MeZO, AGZO, LOZO and LoREN sources with independent environments. Add direct in-place fix/adjust/node training, derived history-free basis gradients, development-best checkpoints and experiment tooling. Keep models, datasets, caches and credentials outside Git.

Validation: 93 project tests passed; 521 vendored author files verified.
This commit is contained in:
gloamxun committed 2026-11-12 23:32:33 +08:00
commit e0feabec8f
596 files changed
+87356

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
import torch
import torch.nn.functional as F
class LegacyLoss:
"""Keep the previous loss and efficient readout exactly for equivalence testing."""
def __init__(self,model,tokenizer,task):
from types import SimpleNamespace
self.model=model;self.args=SimpleNamespace(task=task.lower())
self.label_ids=[tokenizer.encode(w,add_special_tokens=False)[0] for w in (' terrible',' great')]
def __call__(self,inputs):
hidden=self.model.model(input_ids=inputs['input_ids'],attention_mask=inputs['attention_mask'],use_cache=False).last_hidden_state
if self.args.task=='sst2':
logits=self.model.lm_head(hidden[:,-1])[:,self.label_ids]
losses=F.cross_entropy(logits.float(),inputs['labels'],reduction='none')
else:
shifted=inputs['labels'][:,1:];valid=shifted!=-100
logits=self.model.lm_head(hidden[:,:-1][valid]).float()
token_loss=F.cross_entropy(logits,shifted[valid],reduction='none')
owner=torch.arange(len(hidden),device=hidden.device)[:,None].expand_as(valid)[valid]
losses=torch.zeros(len(hidden),device=hidden.device).scatter_add_(0,owner,token_loss)/valid.sum(1).clamp_min(1)
if not bool(torch.isfinite(losses).all()):raise FloatingPointError('Nonfinite loss')
return losses,logits