Delete __init__.py with huggingface_hub
Browse files- __init__.py +0 -327
__init__.py
DELETED
|
@@ -1,327 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
CNN-BiGRU — Modelo Multimodal Cooperativo Autoaprendível (v3.0)
|
| 3 |
-
|
| 4 |
-
Implementação completa de um LLM multimodal com arquitetura CNN-BiGRU cooperativa:
|
| 5 |
-
- Núcleo dual-stream CNN-BiGRU com 3 níveis de pontes (cross-attention, gated cells, fusão)
|
| 6 |
-
- Encoders multimodais (imagem + áudio) com fusão gated
|
| 7 |
-
- Gerador + Verificador + Camada anti-alucinação (lógica fuzzy de Łukasiewicz)
|
| 8 |
-
- Auto-aprendizado: ajuste dinâmico de LR, spectral norm, orthogonal init
|
| 9 |
-
- Hipóteses ativadas por punições (Gumbel-Softmax diferenciável)
|
| 10 |
-
- Synergy search (N tentativas de combinação de hiperparâmetros)
|
| 11 |
-
- Múltiplas funções de perda: L_G, L_V, L_AH, L_reg, L_EWC
|
| 12 |
-
|
| 13 |
-
v2.0:
|
| 14 |
-
- EWC (Elastic Weight Consolidation) para aprendizado contínuo
|
| 15 |
-
- Context Window com cache KV (sliding window + sink)
|
| 16 |
-
- RoPE (Rotary Position Embeddings)
|
| 17 |
-
- TransformerBlock (CausalSelfAttention + FFN)
|
| 18 |
-
- Self-attention final layer verdadeira (CLS-token + multi-head)
|
| 19 |
-
- Weight tying opcional
|
| 20 |
-
- Inferência autoregressiva REAL via GeneratorCNNBiGRU
|
| 21 |
-
|
| 22 |
-
NOVO v3.0:
|
| 23 |
-
- Cyclic Reasoning (Raciocínio Cíclico) com convergência antecipada
|
| 24 |
-
- NLG (Natural Language Generation) com Transformer Decoder + Medusa MTP
|
| 25 |
-
- NLP (Natural Language Processing) com 4 tarefas: SeqCls, TokCls, Span, Embed
|
| 26 |
-
- W8A8 Quantization via SmoothQuant (alpha=0.5, per-channel)
|
| 27 |
-
- VQ-VAE-2 Hierárquico (top + bottom codebooks, EMA update)
|
| 28 |
-
- Multi-Token Prediction (MTP) com Medusa Heads
|
| 29 |
-
- Multimodal Multi-Head Attention (cross-modal + modality gate)
|
| 30 |
-
- Long Context Window (1M tokens) via chunked / ring attention
|
| 31 |
-
- Monitor completo (treino, inferência, evolução, sistema)
|
| 32 |
-
"""
|
| 33 |
-
from __future__ import annotations
|
| 34 |
-
|
| 35 |
-
__version__ = "3.0.0"
|
| 36 |
-
__author__ = "CNN-BiGRU Project"
|
| 37 |
-
|
| 38 |
-
# Versão e metadados
|
| 39 |
-
__all__ = [
|
| 40 |
-
"__version__",
|
| 41 |
-
"__author__",
|
| 42 |
-
# Tokenizer
|
| 43 |
-
"BBPETokenizer",
|
| 44 |
-
# Utils
|
| 45 |
-
"MemoryOptimizer",
|
| 46 |
-
"SemanticEmbedder",
|
| 47 |
-
"EWCConfig",
|
| 48 |
-
"EWCState",
|
| 49 |
-
"W8A8Config",
|
| 50 |
-
"SmoothQuantizer",
|
| 51 |
-
"quantize_model_w8a8",
|
| 52 |
-
"estimate_memory_savings",
|
| 53 |
-
"VQVAE2Config",
|
| 54 |
-
"VQVAE2",
|
| 55 |
-
"Monitor",
|
| 56 |
-
"get_monitor",
|
| 57 |
-
# Runtime
|
| 58 |
-
"optimize_xeon_environment",
|
| 59 |
-
"get_runtime_info",
|
| 60 |
-
# Data
|
| 61 |
-
"MultimodalStreamingDataset",
|
| 62 |
-
"collate_multimodal",
|
| 63 |
-
# Models
|
| 64 |
-
"CooperativeCNNBiGRU",
|
| 65 |
-
"MultimodalCNNBiGRU",
|
| 66 |
-
"ImageEncoder",
|
| 67 |
-
"AudioEncoder",
|
| 68 |
-
"MultimodalFusion",
|
| 69 |
-
"GeneratorCNNBiGRU",
|
| 70 |
-
"VerifierCNNBiGRU",
|
| 71 |
-
"AntiHallucinationLayer",
|
| 72 |
-
"RotaryPositionEmbedding",
|
| 73 |
-
"CausalSelfAttention",
|
| 74 |
-
"TransformerBlock",
|
| 75 |
-
"TransformerDecoderStack",
|
| 76 |
-
"KVCache",
|
| 77 |
-
"ContextWindowManager",
|
| 78 |
-
"ContextWindowConfig",
|
| 79 |
-
"LongContextConfig",
|
| 80 |
-
"LongContextManager",
|
| 81 |
-
"make_long_context_window",
|
| 82 |
-
"CyclicReasoningConfig",
|
| 83 |
-
"CyclicReasoning",
|
| 84 |
-
"MedusaConfig",
|
| 85 |
-
"MedusaMTP",
|
| 86 |
-
"MedusaHead",
|
| 87 |
-
"medusa_tree_decode",
|
| 88 |
-
"NLGConfig",
|
| 89 |
-
"NLGModule",
|
| 90 |
-
"NLPConfig",
|
| 91 |
-
"NLPModule",
|
| 92 |
-
"SequenceClassificationHead",
|
| 93 |
-
"TokenClassificationHead",
|
| 94 |
-
"SpanDetectionHead",
|
| 95 |
-
"EmbeddingHead",
|
| 96 |
-
"MultimodalAttentionConfig",
|
| 97 |
-
"MultimodalMultiHeadAttention",
|
| 98 |
-
"CrossModalAttention",
|
| 99 |
-
"ModalityGate",
|
| 100 |
-
# Losses
|
| 101 |
-
"LossConfig",
|
| 102 |
-
"MultiLoss",
|
| 103 |
-
# Training
|
| 104 |
-
"TrainerConfig",
|
| 105 |
-
"CooperativeTrainer",
|
| 106 |
-
"AutoLearnConfig",
|
| 107 |
-
"AutoLearner",
|
| 108 |
-
"HypothesisConfig",
|
| 109 |
-
"HypothesisController",
|
| 110 |
-
"SynergySearcher",
|
| 111 |
-
# Inference
|
| 112 |
-
"generate_with_sampling",
|
| 113 |
-
"evaluate_perplexity",
|
| 114 |
-
]
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
# Lazy imports — apenas quando acessado
|
| 118 |
-
def __getattr__(name: str):
|
| 119 |
-
if name in ("BBPETokenizer",):
|
| 120 |
-
from .tokenizer.bbpe_tokenizer import BBPETokenizer
|
| 121 |
-
return BBPETokenizer
|
| 122 |
-
if name in ("MemoryOptimizer",):
|
| 123 |
-
from .utils.memory_optimizer import MemoryOptimizer
|
| 124 |
-
return MemoryOptimizer
|
| 125 |
-
if name in ("SemanticEmbedder",):
|
| 126 |
-
from .utils.semantic_embeddings import SemanticEmbedder
|
| 127 |
-
return SemanticEmbedder
|
| 128 |
-
if name in ("EWCConfig", "EWCState"):
|
| 129 |
-
from .utils.ewc import EWCConfig, EWCState
|
| 130 |
-
if name == "EWCConfig":
|
| 131 |
-
return EWCConfig
|
| 132 |
-
return EWCState
|
| 133 |
-
# W8A8 Quantization
|
| 134 |
-
if name in ("W8A8Config", "SmoothQuantizer"):
|
| 135 |
-
from .utils.quantization import W8A8Config, SmoothQuantizer
|
| 136 |
-
if name == "W8A8Config":
|
| 137 |
-
return W8A8Config
|
| 138 |
-
return SmoothQuantizer
|
| 139 |
-
if name == "quantize_model_w8a8":
|
| 140 |
-
from .utils.quantization import quantize_model_w8a8
|
| 141 |
-
return quantize_model_w8a8
|
| 142 |
-
if name == "estimate_memory_savings":
|
| 143 |
-
from .utils.quantization import estimate_memory_savings
|
| 144 |
-
return estimate_memory_savings
|
| 145 |
-
# VQ-VAE-2
|
| 146 |
-
if name in ("VQVAE2Config", "VQVAE2"):
|
| 147 |
-
from .utils.vqvae2 import VQVAE2Config, VQVAE2
|
| 148 |
-
if name == "VQVAE2Config":
|
| 149 |
-
return VQVAE2Config
|
| 150 |
-
return VQVAE2
|
| 151 |
-
# Monitor
|
| 152 |
-
if name in ("Monitor", "get_monitor"):
|
| 153 |
-
from .utils.monitoring import Monitor, get_monitor
|
| 154 |
-
if name == "Monitor":
|
| 155 |
-
return Monitor
|
| 156 |
-
return get_monitor
|
| 157 |
-
# Runtime
|
| 158 |
-
if name in ("optimize_xeon_environment", "get_runtime_info"):
|
| 159 |
-
from .utils import xeon_runtime
|
| 160 |
-
if name == "optimize_xeon_environment":
|
| 161 |
-
return xeon_runtime.optimize_xeon_environment
|
| 162 |
-
return xeon_runtime.get_runtime_info
|
| 163 |
-
# Data
|
| 164 |
-
if name in ("MultimodalStreamingDataset", "collate_multimodal"):
|
| 165 |
-
from .data.streaming_dataset import MultimodalStreamingDataset, collate_multimodal
|
| 166 |
-
if name == "MultimodalStreamingDataset":
|
| 167 |
-
return MultimodalStreamingDataset
|
| 168 |
-
return collate_multimodal
|
| 169 |
-
# Models
|
| 170 |
-
if name == "CooperativeCNNBiGRU":
|
| 171 |
-
from .models.cooperative_bigru import CooperativeCNNBiGRU
|
| 172 |
-
return CooperativeCNNBiGRU
|
| 173 |
-
if name == "MultimodalCNNBiGRU":
|
| 174 |
-
from .models.multimodal_model import MultimodalCNNBiGRU
|
| 175 |
-
return MultimodalCNNBiGRU
|
| 176 |
-
if name in ("ImageEncoder", "AudioEncoder", "MultimodalFusion"):
|
| 177 |
-
from .models.multimodal_encoders import ImageEncoder, AudioEncoder, MultimodalFusion
|
| 178 |
-
if name == "ImageEncoder":
|
| 179 |
-
return ImageEncoder
|
| 180 |
-
if name == "AudioEncoder":
|
| 181 |
-
return AudioEncoder
|
| 182 |
-
return MultimodalFusion
|
| 183 |
-
if name in ("GeneratorCNNBiGRU", "VerifierCNNBiGRU", "AntiHallucinationLayer"):
|
| 184 |
-
from .models.generator_verifier import (
|
| 185 |
-
GeneratorCNNBiGRU,
|
| 186 |
-
VerifierCNNBiGRU,
|
| 187 |
-
AntiHallucinationLayer,
|
| 188 |
-
)
|
| 189 |
-
if name == "GeneratorCNNBiGRU":
|
| 190 |
-
return GeneratorCNNBiGRU
|
| 191 |
-
if name == "VerifierCNNBiGRU":
|
| 192 |
-
return VerifierCNNBiGRU
|
| 193 |
-
return AntiHallucinationLayer
|
| 194 |
-
if name == "RotaryPositionEmbedding":
|
| 195 |
-
from .models.rope import RotaryPositionEmbedding
|
| 196 |
-
return RotaryPositionEmbedding
|
| 197 |
-
if name in ("CausalSelfAttention", "TransformerBlock", "TransformerDecoderStack"):
|
| 198 |
-
from .models.transformer_block import (
|
| 199 |
-
CausalSelfAttention,
|
| 200 |
-
TransformerBlock,
|
| 201 |
-
TransformerDecoderStack,
|
| 202 |
-
)
|
| 203 |
-
if name == "CausalSelfAttention":
|
| 204 |
-
return CausalSelfAttention
|
| 205 |
-
if name == "TransformerBlock":
|
| 206 |
-
return TransformerBlock
|
| 207 |
-
return TransformerDecoderStack
|
| 208 |
-
# Context window (incl. 1M tokens)
|
| 209 |
-
if name in ("KVCache", "ContextWindowManager", "ContextWindowConfig"):
|
| 210 |
-
from .models.context_window import KVCache, ContextWindowManager, ContextWindowConfig
|
| 211 |
-
if name == "KVCache":
|
| 212 |
-
return KVCache
|
| 213 |
-
if name == "ContextWindowManager":
|
| 214 |
-
return ContextWindowManager
|
| 215 |
-
return ContextWindowConfig
|
| 216 |
-
if name in ("LongContextConfig", "LongContextManager", "make_long_context_window"):
|
| 217 |
-
from .models.context_window import (
|
| 218 |
-
LongContextConfig,
|
| 219 |
-
LongContextManager,
|
| 220 |
-
make_long_context_window,
|
| 221 |
-
)
|
| 222 |
-
if name == "LongContextConfig":
|
| 223 |
-
return LongContextConfig
|
| 224 |
-
if name == "LongContextManager":
|
| 225 |
-
return LongContextManager
|
| 226 |
-
return make_long_context_window
|
| 227 |
-
# Cyclic Reasoning
|
| 228 |
-
if name in ("CyclicReasoningConfig", "CyclicReasoning"):
|
| 229 |
-
from .models.cyclic_reasoning import CyclicReasoningConfig, CyclicReasoning
|
| 230 |
-
if name == "CyclicReasoningConfig":
|
| 231 |
-
return CyclicReasoningConfig
|
| 232 |
-
return CyclicReasoning
|
| 233 |
-
# Medusa MTP
|
| 234 |
-
if name in ("MedusaConfig", "MedusaMTP", "MedusaHead", "medusa_tree_decode"):
|
| 235 |
-
from .models.medusa_heads import (
|
| 236 |
-
MedusaConfig,
|
| 237 |
-
MedusaMTP,
|
| 238 |
-
MedusaHead,
|
| 239 |
-
medusa_tree_decode,
|
| 240 |
-
)
|
| 241 |
-
if name == "MedusaConfig":
|
| 242 |
-
return MedusaConfig
|
| 243 |
-
if name == "MedusaMTP":
|
| 244 |
-
return MedusaMTP
|
| 245 |
-
if name == "MedusaHead":
|
| 246 |
-
return MedusaHead
|
| 247 |
-
return medusa_tree_decode
|
| 248 |
-
# NLG
|
| 249 |
-
if name in ("NLGConfig", "NLGModule"):
|
| 250 |
-
from .models.nlg import NLGConfig, NLGModule
|
| 251 |
-
if name == "NLGConfig":
|
| 252 |
-
return NLGConfig
|
| 253 |
-
return NLGModule
|
| 254 |
-
# NLP
|
| 255 |
-
if name in ("NLPConfig", "NLPModule",
|
| 256 |
-
"SequenceClassificationHead", "TokenClassificationHead",
|
| 257 |
-
"SpanDetectionHead", "EmbeddingHead"):
|
| 258 |
-
from .models.nlp import (
|
| 259 |
-
NLPConfig,
|
| 260 |
-
NLPModule,
|
| 261 |
-
SequenceClassificationHead,
|
| 262 |
-
TokenClassificationHead,
|
| 263 |
-
SpanDetectionHead,
|
| 264 |
-
EmbeddingHead,
|
| 265 |
-
)
|
| 266 |
-
if name == "NLPConfig":
|
| 267 |
-
return NLPConfig
|
| 268 |
-
if name == "NLPModule":
|
| 269 |
-
return NLPModule
|
| 270 |
-
if name == "SequenceClassificationHead":
|
| 271 |
-
return SequenceClassificationHead
|
| 272 |
-
if name == "TokenClassificationHead":
|
| 273 |
-
return TokenClassificationHead
|
| 274 |
-
if name == "SpanDetectionHead":
|
| 275 |
-
return SpanDetectionHead
|
| 276 |
-
return EmbeddingHead
|
| 277 |
-
# Multimodal Attention
|
| 278 |
-
if name in ("MultimodalAttentionConfig", "MultimodalMultiHeadAttention",
|
| 279 |
-
"CrossModalAttention", "ModalityGate"):
|
| 280 |
-
from .models.multimodal_attention import (
|
| 281 |
-
MultimodalAttentionConfig,
|
| 282 |
-
MultimodalMultiHeadAttention,
|
| 283 |
-
CrossModalAttention,
|
| 284 |
-
ModalityGate,
|
| 285 |
-
)
|
| 286 |
-
if name == "MultimodalAttentionConfig":
|
| 287 |
-
return MultimodalAttentionConfig
|
| 288 |
-
if name == "MultimodalMultiHeadAttention":
|
| 289 |
-
return MultimodalMultiHeadAttention
|
| 290 |
-
if name == "CrossModalAttention":
|
| 291 |
-
return CrossModalAttention
|
| 292 |
-
return ModalityGate
|
| 293 |
-
# Losses
|
| 294 |
-
if name in ("LossConfig", "MultiLoss"):
|
| 295 |
-
from .losses.losses import LossConfig, MultiLoss
|
| 296 |
-
if name == "LossConfig":
|
| 297 |
-
return LossConfig
|
| 298 |
-
return MultiLoss
|
| 299 |
-
# Training
|
| 300 |
-
if name in ("TrainerConfig", "CooperativeTrainer"):
|
| 301 |
-
from .training.trainer import TrainerConfig, CooperativeTrainer
|
| 302 |
-
if name == "TrainerConfig":
|
| 303 |
-
return TrainerConfig
|
| 304 |
-
return CooperativeTrainer
|
| 305 |
-
if name in ("AutoLearnConfig", "AutoLearner"):
|
| 306 |
-
from .training.auto_learner import AutoLearnConfig, AutoLearner
|
| 307 |
-
if name == "AutoLearnConfig":
|
| 308 |
-
return AutoLearnConfig
|
| 309 |
-
return AutoLearner
|
| 310 |
-
if name in ("HypothesisConfig", "HypothesisController", "SynergySearcher"):
|
| 311 |
-
from .training.hypothesis_controller import (
|
| 312 |
-
HypothesisConfig,
|
| 313 |
-
HypothesisController,
|
| 314 |
-
SynergySearcher,
|
| 315 |
-
)
|
| 316 |
-
if name == "HypothesisConfig":
|
| 317 |
-
return HypothesisConfig
|
| 318 |
-
if name == "HypothesisController":
|
| 319 |
-
return HypothesisController
|
| 320 |
-
return SynergySearcher
|
| 321 |
-
# Inference
|
| 322 |
-
if name in ("generate_with_sampling", "evaluate_perplexity"):
|
| 323 |
-
from .inference.inference import generate_with_sampling, evaluate_perplexity
|
| 324 |
-
if name == "generate_with_sampling":
|
| 325 |
-
return generate_with_sampling
|
| 326 |
-
return evaluate_perplexity
|
| 327 |
-
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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