Update configuration_neollm.py
Browse files- configuration_neollm.py +80 -1
configuration_neollm.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
# ==================== configuration_neollm.py ====================
|
|
|
|
|
|
|
| 2 |
from transformers.configuration_utils import PretrainedConfig
|
| 3 |
from transformers.modeling_rope_utils import rope_config_validation
|
| 4 |
from transformers.utils import logging
|
|
@@ -62,6 +64,33 @@ class NeoLLMConfig(PretrainedConfig):
|
|
| 62 |
CCE implementation used when ``ntp_loss_backend="cce"``. The default
|
| 63 |
keeps the conservative Kahan/full-classifier-gradient path used for
|
| 64 |
pretraining from scratch.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
liger_loss_accum_dtype (:obj:`str`, *optional*, defaults to ``"float32"``):
|
| 66 |
Accumulator dtype passed to Liger FLCE for weight/bias gradient
|
| 67 |
accumulation. ``"float32"`` is the stability-first setting for BF16
|
|
@@ -742,6 +771,17 @@ class NeoLLMConfig(PretrainedConfig):
|
|
| 742 |
ntp_loss_backend="cce",
|
| 743 |
use_liger_kernel=False,
|
| 744 |
cce_loss_impl="cce_kahan_full_c",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 745 |
liger_loss_accum_dtype="float32",
|
| 746 |
rope_theta=10000.0,
|
| 747 |
rope_scaling=None,
|
|
@@ -851,7 +891,7 @@ class NeoLLMConfig(PretrainedConfig):
|
|
| 851 |
# `nitp_temporal_apply_loss=False` keeps the module instantiated and
|
| 852 |
# computes every diagnostic metric, but does not add its objective to
|
| 853 |
# the model loss. This is the requested monitoring-only ablation.
|
| 854 |
-
use_nitp_temporal=
|
| 855 |
nitp_temporal_apply_loss=False,
|
| 856 |
nitp_temporal_horizon=4,
|
| 857 |
nitp_temporal_dynamics_weight=1.0,
|
|
@@ -888,6 +928,33 @@ class NeoLLMConfig(PretrainedConfig):
|
|
| 888 |
if not str(cce_loss_impl).strip():
|
| 889 |
raise ValueError("`cce_loss_impl` must be a non-empty string.")
|
| 890 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 891 |
_valid_liger_accum_dtypes = {
|
| 892 |
None,
|
| 893 |
"",
|
|
@@ -1217,6 +1284,18 @@ class NeoLLMConfig(PretrainedConfig):
|
|
| 1217 |
self.ntp_loss_backend = ntp_loss_backend
|
| 1218 |
self.use_liger_kernel = bool(use_liger_kernel)
|
| 1219 |
self.cce_loss_impl = str(cce_loss_impl).strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1220 |
self.liger_loss_accum_dtype = liger_loss_accum_dtype
|
| 1221 |
|
| 1222 |
# ── Positional encoding ───────────────────────────────────────────
|
|
|
|
| 1 |
# ==================== configuration_neollm.py ====================
|
| 2 |
+
import math
|
| 3 |
+
|
| 4 |
from transformers.configuration_utils import PretrainedConfig
|
| 5 |
from transformers.modeling_rope_utils import rope_config_validation
|
| 6 |
from transformers.utils import logging
|
|
|
|
| 64 |
CCE implementation used when ``ntp_loss_backend="cce"``. The default
|
| 65 |
keeps the conservative Kahan/full-classifier-gradient path used for
|
| 66 |
pretraining from scratch.
|
| 67 |
+
use_mile_loss (:obj:`bool`, *optional*, defaults to ``False``):
|
| 68 |
+
Enable MiLe Loss (Su et al., 2026, arXiv:2310.19531) in the extended
|
| 69 |
+
CCE backend. MiLe reweights token losses with detached,
|
| 70 |
+
mean-normalized predictive-entropy weights.
|
| 71 |
+
mile_loss_gamma (:obj:`float`, *optional*, defaults to ``1.0``):
|
| 72 |
+
Non-negative exponent applied to MiLe's ``1 + entropy`` weight.
|
| 73 |
+
use_mu_loss (:obj:`bool`, *optional*, defaults to ``False``):
|
| 74 |
+
Enable the output-embedding centering regularizer from Stollenwerk
|
| 75 |
+
et al. (2026, arXiv:2601.02031) in the extended CCE backend.
|
| 76 |
+
mu_loss_lambda (:obj:`float`, *optional*, defaults to ``1e-4``):
|
| 77 |
+
Non-negative coefficient in ``L_mu = lambda * ||mean(C)||^2``.
|
| 78 |
+
use_meap (:obj:`bool`, *optional*, defaults to ``False``):
|
| 79 |
+
Enable Mask-Enhanced Autoregressive Prediction during training only
|
| 80 |
+
(Zhuang et al., 2026, arXiv:2502.07490). Labels and attention masks
|
| 81 |
+
remain clean; only selected input token IDs are replaced.
|
| 82 |
+
meap_mask_ratio (:obj:`float`, *optional*, defaults to ``0.15``):
|
| 83 |
+
Fraction of eligible input positions replaced in each sequence.
|
| 84 |
+
meap_mask_token_id (:obj:`int`, *optional*):
|
| 85 |
+
Token ID used as the MEAP replacement. Required when MEAP is enabled.
|
| 86 |
+
meap_seed (:obj:`int`, *optional*, defaults to ``0``):
|
| 87 |
+
Base 32-bit seed. The Trainer derives a distinct deterministic seed
|
| 88 |
+
for each microstep and distributed process.
|
| 89 |
+
meap_implementation (:obj:`str`, *optional*, defaults to ``"triton"``):
|
| 90 |
+
MEAP implementation, either ``"triton"`` or the reference
|
| 91 |
+
``"torch"`` path.
|
| 92 |
+
meap_exclude_last (:obj:`bool`, *optional*, defaults to ``True``):
|
| 93 |
+
Exclude the final eligible input because it has no shifted target.
|
| 94 |
liger_loss_accum_dtype (:obj:`str`, *optional*, defaults to ``"float32"``):
|
| 95 |
Accumulator dtype passed to Liger FLCE for weight/bias gradient
|
| 96 |
accumulation. ``"float32"`` is the stability-first setting for BF16
|
|
|
|
| 771 |
ntp_loss_backend="cce",
|
| 772 |
use_liger_kernel=False,
|
| 773 |
cce_loss_impl="cce_kahan_full_c",
|
| 774 |
+
# ── Optional extended-CCE objectives and MEAP input corruption ────
|
| 775 |
+
use_mile_loss=True,
|
| 776 |
+
mile_loss_gamma=1.0,
|
| 777 |
+
use_mu_loss=True,
|
| 778 |
+
mu_loss_lambda=1e-4,
|
| 779 |
+
use_meap=False,
|
| 780 |
+
meap_mask_ratio=0.15,
|
| 781 |
+
meap_mask_token_id=None,
|
| 782 |
+
meap_seed=0,
|
| 783 |
+
meap_implementation="triton",
|
| 784 |
+
meap_exclude_last=True,
|
| 785 |
liger_loss_accum_dtype="float32",
|
| 786 |
rope_theta=10000.0,
|
| 787 |
rope_scaling=None,
|
|
|
|
| 891 |
# `nitp_temporal_apply_loss=False` keeps the module instantiated and
|
| 892 |
# computes every diagnostic metric, but does not add its objective to
|
| 893 |
# the model loss. This is the requested monitoring-only ablation.
|
| 894 |
+
use_nitp_temporal=False,
|
| 895 |
nitp_temporal_apply_loss=False,
|
| 896 |
nitp_temporal_horizon=4,
|
| 897 |
nitp_temporal_dynamics_weight=1.0,
|
|
|
|
| 928 |
if not str(cce_loss_impl).strip():
|
| 929 |
raise ValueError("`cce_loss_impl` must be a non-empty string.")
|
| 930 |
|
| 931 |
+
if (use_mile_loss or use_mu_loss) and ntp_loss_backend != "cce":
|
| 932 |
+
raise ValueError(
|
| 933 |
+
"MiLe and mu-loss require `ntp_loss_backend='cce'`; they are "
|
| 934 |
+
"not implemented by the Liger loss backend."
|
| 935 |
+
)
|
| 936 |
+
if not math.isfinite(float(mile_loss_gamma)) or mile_loss_gamma < 0.0:
|
| 937 |
+
raise ValueError(
|
| 938 |
+
f"`mile_loss_gamma` must be finite and >= 0, got {mile_loss_gamma}."
|
| 939 |
+
)
|
| 940 |
+
if not math.isfinite(float(mu_loss_lambda)) or mu_loss_lambda < 0.0:
|
| 941 |
+
raise ValueError(
|
| 942 |
+
f"`mu_loss_lambda` must be finite and >= 0, got {mu_loss_lambda}."
|
| 943 |
+
)
|
| 944 |
+
if not math.isfinite(float(meap_mask_ratio)) or not 0.0 <= meap_mask_ratio <= 1.0:
|
| 945 |
+
raise ValueError(
|
| 946 |
+
f"`meap_mask_ratio` must be finite and in [0, 1], got {meap_mask_ratio}."
|
| 947 |
+
)
|
| 948 |
+
if use_meap and meap_mask_token_id is None:
|
| 949 |
+
raise ValueError("`meap_mask_token_id` is required when `use_meap=True`.")
|
| 950 |
+
if meap_mask_token_id is not None and int(meap_mask_token_id) < 0:
|
| 951 |
+
raise ValueError("`meap_mask_token_id` must be a non-negative integer.")
|
| 952 |
+
if not isinstance(meap_seed, int) or not 0 <= meap_seed <= 0xFFFFFFFF:
|
| 953 |
+
raise ValueError("`meap_seed` must be an integer in [0, 2**32 - 1].")
|
| 954 |
+
meap_implementation = str(meap_implementation).strip().lower()
|
| 955 |
+
if meap_implementation not in {"triton", "torch"}:
|
| 956 |
+
raise ValueError("`meap_implementation` must be 'triton' or 'torch'.")
|
| 957 |
+
|
| 958 |
_valid_liger_accum_dtypes = {
|
| 959 |
None,
|
| 960 |
"",
|
|
|
|
| 1284 |
self.ntp_loss_backend = ntp_loss_backend
|
| 1285 |
self.use_liger_kernel = bool(use_liger_kernel)
|
| 1286 |
self.cce_loss_impl = str(cce_loss_impl).strip()
|
| 1287 |
+
self.use_mile_loss = bool(use_mile_loss)
|
| 1288 |
+
self.mile_loss_gamma = float(mile_loss_gamma)
|
| 1289 |
+
self.use_mu_loss = bool(use_mu_loss)
|
| 1290 |
+
self.mu_loss_lambda = float(mu_loss_lambda)
|
| 1291 |
+
self.use_meap = bool(use_meap)
|
| 1292 |
+
self.meap_mask_ratio = float(meap_mask_ratio)
|
| 1293 |
+
self.meap_mask_token_id = (
|
| 1294 |
+
None if meap_mask_token_id is None else int(meap_mask_token_id)
|
| 1295 |
+
)
|
| 1296 |
+
self.meap_seed = int(meap_seed)
|
| 1297 |
+
self.meap_implementation = meap_implementation
|
| 1298 |
+
self.meap_exclude_last = bool(meap_exclude_last)
|
| 1299 |
self.liger_loss_accum_dtype = liger_loss_accum_dtype
|
| 1300 |
|
| 1301 |
# ── Positional encoding ───────────────────────────────────────────
|