Upload 3 files
Browse files- 2Gv37_AutoLR/emoairy.py +4 -4
- 2Gv37_AutoLR/emocats.py +16 -28
- 2Gv37_AutoLR/emosens.py +3 -3
2Gv37_AutoLR/emoairy.py
CHANGED
|
@@ -31,9 +31,9 @@ class EmoAiry(Optimizer):
|
|
| 31 |
# 感情EMA更新(緊張と安静)
|
| 32 |
def _update_ema(self, state, loss_val):
|
| 33 |
ema = state.setdefault('ema', {})
|
| 34 |
-
ema['short']
|
| 35 |
ema['medium'] = 0.05 * loss_val + 0.95 * ema.get('medium', loss_val)
|
| 36 |
-
ema['long']
|
| 37 |
return ema
|
| 38 |
|
| 39 |
# 感情スカラー値生成(EMA差分、滑らかな非線形スカラー、tanh(diff) は ±1.0 で有界性)
|
|
@@ -154,8 +154,8 @@ class EmoAiry(Optimizer):
|
|
| 154 |
update_term = grad / denom
|
| 155 |
|
| 156 |
# 最終的なパラメータ更新 (decoupled weight decayも適用)
|
| 157 |
-
# sign化で2次moment
|
| 158 |
-
p.
|
| 159 |
p.add_(update_term.sign_(), alpha=-emoPulse)
|
| 160 |
# --- End Gradient Update Logic ---
|
| 161 |
|
|
|
|
| 31 |
# 感情EMA更新(緊張と安静)
|
| 32 |
def _update_ema(self, state, loss_val):
|
| 33 |
ema = state.setdefault('ema', {})
|
| 34 |
+
ema['short'] = 0.3 * loss_val + 0.7 * ema.get('short', loss_val)
|
| 35 |
ema['medium'] = 0.05 * loss_val + 0.95 * ema.get('medium', loss_val)
|
| 36 |
+
ema['long'] = 0.01 * loss_val + 0.99 * ema.get('long', loss_val)
|
| 37 |
return ema
|
| 38 |
|
| 39 |
# 感情スカラー値生成(EMA差分、滑らかな非線形スカラー、tanh(diff) は ±1.0 で有界性)
|
|
|
|
| 154 |
update_term = grad / denom
|
| 155 |
|
| 156 |
# 最終的なパラメータ更新 (decoupled weight decayも適用)
|
| 157 |
+
# sign化で2次momentと1次ベクトルのデータの質(粒度)を揃える
|
| 158 |
+
p.mul_(1.0 - group['weight_decay'] * emoPulse)
|
| 159 |
p.add_(update_term.sign_(), alpha=-emoPulse)
|
| 160 |
# --- End Gradient Update Logic ---
|
| 161 |
|
2Gv37_AutoLR/emocats.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import torch
|
| 2 |
from torch.optim import Optimizer
|
| 3 |
import math
|
| 4 |
-
from typing import Callable
|
| 5 |
|
| 6 |
"""
|
| 7 |
EmoCats v3.7.6 (260109) shadow-system v3.1 -moment v3.1 emoPulse v3.7
|
|
@@ -11,18 +10,14 @@ dNR係数により emoPulse に履歴を混ぜて安定させた(d / N 履歴
|
|
| 11 |
Early scalar、Early Stop、効率化しつつ精度向上させ負荷も軽減する等の改修と微調整
|
| 12 |
"""
|
| 13 |
|
| 14 |
-
# Helper function
|
| 15 |
-
def exists(val):
|
| 16 |
-
return val is not None
|
| 17 |
-
|
| 18 |
class EmoCats(Optimizer):
|
| 19 |
-
# クラス定義&初期化
|
| 20 |
-
def __init__(self, params,
|
| 21 |
-
lr=1.0,
|
| 22 |
-
eps=1e-8,
|
| 23 |
-
betas=(0.9, 0.995),
|
| 24 |
-
weight_decay=0.01,
|
| 25 |
-
use_shadow:
|
| 26 |
defaults = dict(lr=lr, betas=betas, eps=eps, weight_decay=weight_decay)
|
| 27 |
super().__init__(params, defaults)
|
| 28 |
self._init_lr = lr
|
|
@@ -36,9 +31,9 @@ class EmoCats(Optimizer):
|
|
| 36 |
# 感情EMA更新(緊張と安静)
|
| 37 |
def _update_ema(self, state, loss_val):
|
| 38 |
ema = state.setdefault('ema', {})
|
| 39 |
-
ema['short']
|
| 40 |
ema['medium'] = 0.05 * loss_val + 0.95 * ema.get('medium', loss_val)
|
| 41 |
-
ema['long']
|
| 42 |
return ema
|
| 43 |
|
| 44 |
# 感情スカラー値生成(EMA差分、滑らかな非線形スカラー、tanh(diff) は ±1.0 で有界性)
|
|
@@ -75,11 +70,8 @@ class EmoCats(Optimizer):
|
|
| 75 |
|
| 76 |
# 損失取得(損失値 loss_val を数値化、感情判定に使用、存在しないパラメータ(更新不要)はスキップ)
|
| 77 |
@torch.no_grad()
|
| 78 |
-
def step(self, closure
|
| 79 |
-
loss = None
|
| 80 |
-
if exists(closure): # 一貫性のためにexistsヘルパーを使う
|
| 81 |
-
with torch.enable_grad():
|
| 82 |
-
loss = closure()
|
| 83 |
loss_val = loss.item() if loss is not None else 0.0
|
| 84 |
|
| 85 |
# EMA更新・スカラー生成(EMA差分からスカラーを生成しスパイク比率等を決定)
|
|
@@ -112,10 +104,8 @@ class EmoCats(Optimizer):
|
|
| 112 |
# --- End emoPulse (完全自動LR生成) ---
|
| 113 |
|
| 114 |
for group in self.param_groups:
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
# PGチェックにフィルタ
|
| 118 |
-
for p in filter(lambda p: exists(p.grad), group['params']):
|
| 119 |
|
| 120 |
grad = p.grad
|
| 121 |
state = self.state[p]
|
|
@@ -140,15 +130,14 @@ class EmoCats(Optimizer):
|
|
| 140 |
state['exp_avg'] = torch.zeros_like(p)
|
| 141 |
exp_avg = state['exp_avg']
|
| 142 |
|
| 143 |
-
#
|
| 144 |
-
p.mul_(1 -
|
| 145 |
-
beta1, beta2 = group['betas']
|
| 146 |
|
| 147 |
# 勾配ブレンド
|
| 148 |
blended_grad = grad.mul(1 - beta1).add(exp_avg, alpha=beta1)
|
| 149 |
|
| 150 |
# 最終的なパラメータ更新
|
| 151 |
-
p.add_(blended_grad.
|
| 152 |
exp_avg.mul_(beta2).add_(grad, alpha = 1 - beta2)
|
| 153 |
# --- End Gradient Update Logic ---
|
| 154 |
|
|
@@ -171,5 +160,4 @@ class EmoCats(Optimizer):
|
|
| 171 |
https://github.com/muooon/EmoSens
|
| 172 |
Cats was developed with inspiration from Lion, Tiger, and emolynx,
|
| 173 |
which we deeply respect for their lightweight and intelligent design.
|
| 174 |
-
Cats also integrates EmoNAVI to enhance its capabilities.
|
| 175 |
"""
|
|
|
|
| 1 |
import torch
|
| 2 |
from torch.optim import Optimizer
|
| 3 |
import math
|
|
|
|
| 4 |
|
| 5 |
"""
|
| 6 |
EmoCats v3.7.6 (260109) shadow-system v3.1 -moment v3.1 emoPulse v3.7
|
|
|
|
| 10 |
Early scalar、Early Stop、効率化しつつ精度向上させ負荷も軽減する等の改修と微調整
|
| 11 |
"""
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
class EmoCats(Optimizer):
|
| 14 |
+
# クラス定義&初期化
|
| 15 |
+
def __init__(self, params,
|
| 16 |
+
lr=1.0,
|
| 17 |
+
eps=1e-8,
|
| 18 |
+
betas=(0.9, 0.995),
|
| 19 |
+
weight_decay=0.01,
|
| 20 |
+
use_shadow:bool=False):
|
| 21 |
defaults = dict(lr=lr, betas=betas, eps=eps, weight_decay=weight_decay)
|
| 22 |
super().__init__(params, defaults)
|
| 23 |
self._init_lr = lr
|
|
|
|
| 31 |
# 感情EMA更新(緊張と安静)
|
| 32 |
def _update_ema(self, state, loss_val):
|
| 33 |
ema = state.setdefault('ema', {})
|
| 34 |
+
ema['short'] = 0.3 * loss_val + 0.7 * ema.get('short', loss_val)
|
| 35 |
ema['medium'] = 0.05 * loss_val + 0.95 * ema.get('medium', loss_val)
|
| 36 |
+
ema['long'] = 0.01 * loss_val + 0.99 * ema.get('long', loss_val)
|
| 37 |
return ema
|
| 38 |
|
| 39 |
# 感情スカラー値生成(EMA差分、滑らかな非線形スカラー、tanh(diff) は ±1.0 で有界性)
|
|
|
|
| 70 |
|
| 71 |
# 損失取得(損失値 loss_val を数値化、感情判定に使用、存在しないパラメータ(更新不要)はスキップ)
|
| 72 |
@torch.no_grad()
|
| 73 |
+
def step(self, closure=None):
|
| 74 |
+
loss = torch.enable_grad()(closure)() if closure is not None else None
|
|
|
|
|
|
|
|
|
|
| 75 |
loss_val = loss.item() if loss is not None else 0.0
|
| 76 |
|
| 77 |
# EMA更新・スカラー生成(EMA差分からスカラーを生成しスパイク比率等を決定)
|
|
|
|
| 104 |
# --- End emoPulse (完全自動LR生成) ---
|
| 105 |
|
| 106 |
for group in self.param_groups:
|
| 107 |
+
beta1, beta2 = group['betas']
|
| 108 |
+
for p in (p for p in group['params'] if p.grad is not None):
|
|
|
|
|
|
|
| 109 |
|
| 110 |
grad = p.grad
|
| 111 |
state = self.state[p]
|
|
|
|
| 130 |
state['exp_avg'] = torch.zeros_like(p)
|
| 131 |
exp_avg = state['exp_avg']
|
| 132 |
|
| 133 |
+
# decoupled weight decay
|
| 134 |
+
p.mul_(1.0 - group['weight_decay'] * emoPulse)
|
|
|
|
| 135 |
|
| 136 |
# 勾配ブレンド
|
| 137 |
blended_grad = grad.mul(1 - beta1).add(exp_avg, alpha=beta1)
|
| 138 |
|
| 139 |
# 最終的なパラメータ更新
|
| 140 |
+
p.add_(blended_grad.sign_(), alpha = -emoPulse)
|
| 141 |
exp_avg.mul_(beta2).add_(grad, alpha = 1 - beta2)
|
| 142 |
# --- End Gradient Update Logic ---
|
| 143 |
|
|
|
|
| 160 |
https://github.com/muooon/EmoSens
|
| 161 |
Cats was developed with inspiration from Lion, Tiger, and emolynx,
|
| 162 |
which we deeply respect for their lightweight and intelligent design.
|
|
|
|
| 163 |
"""
|
2Gv37_AutoLR/emosens.py
CHANGED
|
@@ -31,9 +31,9 @@ class EmoSens(Optimizer):
|
|
| 31 |
# 感情EMA更新(緊張と安静)
|
| 32 |
def _update_ema(self, state, loss_val):
|
| 33 |
ema = state.setdefault('ema', {})
|
| 34 |
-
ema['short']
|
| 35 |
ema['medium'] = 0.05 * loss_val + 0.95 * ema.get('medium', loss_val)
|
| 36 |
-
ema['long']
|
| 37 |
return ema
|
| 38 |
|
| 39 |
# 感情スカラー値生成(EMA差分、滑らかな非線形スカラー、tanh(diff) は ±1.0 で有界性)
|
|
@@ -136,7 +136,7 @@ class EmoSens(Optimizer):
|
|
| 136 |
denom = exp_avg_sq.sqrt().add_(group['eps'])
|
| 137 |
|
| 138 |
if group['weight_decay']:
|
| 139 |
-
p.
|
| 140 |
p.addcdiv_(exp_avg, denom, value=-emoPulse)
|
| 141 |
# --- End Gradient Update Logic ---
|
| 142 |
|
|
|
|
| 31 |
# 感情EMA更新(緊張と安静)
|
| 32 |
def _update_ema(self, state, loss_val):
|
| 33 |
ema = state.setdefault('ema', {})
|
| 34 |
+
ema['short'] = 0.3 * loss_val + 0.7 * ema.get('short', loss_val)
|
| 35 |
ema['medium'] = 0.05 * loss_val + 0.95 * ema.get('medium', loss_val)
|
| 36 |
+
ema['long'] = 0.01 * loss_val + 0.99 * ema.get('long', loss_val)
|
| 37 |
return ema
|
| 38 |
|
| 39 |
# 感情スカラー値生成(EMA差分、滑らかな非線形スカラー、tanh(diff) は ±1.0 で有界性)
|
|
|
|
| 136 |
denom = exp_avg_sq.sqrt().add_(group['eps'])
|
| 137 |
|
| 138 |
if group['weight_decay']:
|
| 139 |
+
p.mul_(1.0 - group['weight_decay'] * emoPulse)
|
| 140 |
p.addcdiv_(exp_avg, denom, value=-emoPulse)
|
| 141 |
# --- End Gradient Update Logic ---
|
| 142 |
|