File size: 6,738 Bytes
eb1f6a4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | """
CNN-BiGRU — Modelo Multimodal Cooperativo Autoaprendível (v2.0)
Implementação completa de um LLM multimodal com arquitetura CNN-BiGRU cooperativa:
- Núcleo dual-stream CNN-BiGRU com 3 níveis de pontes (cross-attention, gated cells, fusão)
- Encoders multimodais (imagem + áudio) com fusão gated
- Gerador + Verificador + Camada anti-alucinação (lógica fuzzy de Łukasiewicz)
- Auto-aprendizado: ajuste dinâmico de LR, spectral norm, orthogonal init
- Hipóteses ativadas por punições (Gumbel-Softmax diferenciável)
- Synergy search (N tentativas de combinação de hiperparâmetros)
- Múltiplas funções de perda: L_G, L_V, L_AH, L_reg, L_EWC
NOVO v2.0:
- EWC (Elastic Weight Consolidation) para aprendizado contínuo
- Context Window com cache KV (sliding window + sink)
- RoPE (Rotary Position Embeddings)
- TransformerBlock (CausalSelfAttention + FFN)
- Self-attention final layer verdadeira (CLS-token + multi-head)
- Weight tying opcional
- Inferência autoregressiva REAL via GeneratorCNNBiGRU
"""
from __future__ import annotations
__version__ = "2.0.0"
__author__ = "CNN-BiGRU Project"
# Versão e metadados
__all__ = [
"__version__",
"__author__",
# Tokenizer
"BBPETokenizer",
# Utils
"MemoryOptimizer",
"SemanticEmbedder",
"EWCConfig",
"EWCState",
# Runtime
"optimize_xeon_environment",
"get_runtime_info",
# Data
"MultimodalStreamingDataset",
"collate_multimodal",
# Models
"CooperativeCNNBiGRU",
"MultimodalCNNBiGRU",
"ImageEncoder",
"AudioEncoder",
"MultimodalFusion",
"GeneratorCNNBiGRU",
"VerifierCNNBiGRU",
"AntiHallucinationLayer",
"RotaryPositionEmbedding",
"CausalSelfAttention",
"TransformerBlock",
"TransformerDecoderStack",
"KVCache",
"ContextWindowManager",
"ContextWindowConfig",
# Losses
"LossConfig",
"MultiLoss",
# Training
"TrainerConfig",
"CooperativeTrainer",
"AutoLearnConfig",
"AutoLearner",
"HypothesisConfig",
"HypothesisController",
"SynergySearcher",
# Inference
"generate_with_sampling",
"evaluate_perplexity",
]
# Lazy imports — apenas quando acessado
def __getattr__(name: str):
if name in ("BBPETokenizer",):
from .tokenizer.bbpe_tokenizer import BBPETokenizer
return BBPETokenizer
if name in ("MemoryOptimizer",):
from .utils.memory_optimizer import MemoryOptimizer
return MemoryOptimizer
if name in ("SemanticEmbedder",):
from .utils.semantic_embeddings import SemanticEmbedder
return SemanticEmbedder
if name in ("EWCConfig", "EWCState"):
from .utils.ewc import EWCConfig, EWCState
if name == "EWCConfig":
return EWCConfig
return EWCState
if name in ("optimize_xeon_environment", "get_runtime_info"):
from .utils import xeon_runtime
if name == "optimize_xeon_environment":
return xeon_runtime.optimize_xeon_environment
return xeon_runtime.get_runtime_info
if name in ("MultimodalStreamingDataset", "collate_multimodal"):
from .data.streaming_dataset import MultimodalStreamingDataset, collate_multimodal
if name == "MultimodalStreamingDataset":
return MultimodalStreamingDataset
return collate_multimodal
if name == "CooperativeCNNBiGRU":
from .models.cooperative_bigru import CooperativeCNNBiGRU
return CooperativeCNNBiGRU
if name == "MultimodalCNNBiGRU":
from .models.multimodal_model import MultimodalCNNBiGRU
return MultimodalCNNBiGRU
if name in ("ImageEncoder", "AudioEncoder", "MultimodalFusion"):
from .models.multimodal_encoders import ImageEncoder, AudioEncoder, MultimodalFusion
if name == "ImageEncoder":
return ImageEncoder
if name == "AudioEncoder":
return AudioEncoder
return MultimodalFusion
if name in ("GeneratorCNNBiGRU", "VerifierCNNBiGRU", "AntiHallucinationLayer"):
from .models.generator_verifier import (
GeneratorCNNBiGRU,
VerifierCNNBiGRU,
AntiHallucinationLayer,
)
if name == "GeneratorCNNBiGRU":
return GeneratorCNNBiGRU
if name == "VerifierCNNBiGRU":
return VerifierCNNBiGRU
return AntiHallucinationLayer
if name == "RotaryPositionEmbedding":
from .models.rope import RotaryPositionEmbedding
return RotaryPositionEmbedding
if name in ("CausalSelfAttention", "TransformerBlock", "TransformerDecoderStack"):
from .models.transformer_block import (
CausalSelfAttention,
TransformerBlock,
TransformerDecoderStack,
)
if name == "CausalSelfAttention":
return CausalSelfAttention
if name == "TransformerBlock":
return TransformerBlock
return TransformerDecoderStack
if name in ("KVCache", "ContextWindowManager", "ContextWindowConfig"):
from .models.context_window import KVCache, ContextWindowManager, ContextWindowConfig
if name == "KVCache":
return KVCache
if name == "ContextWindowManager":
return ContextWindowManager
return ContextWindowConfig
if name in ("LossConfig", "MultiLoss"):
from .losses.losses import LossConfig, MultiLoss
if name == "LossConfig":
return LossConfig
return MultiLoss
if name in ("TrainerConfig", "CooperativeTrainer"):
from .training.trainer import TrainerConfig, CooperativeTrainer
if name == "TrainerConfig":
return TrainerConfig
return CooperativeTrainer
if name in ("AutoLearnConfig", "AutoLearner"):
from .training.auto_learner import AutoLearnConfig, AutoLearner
if name == "AutoLearnConfig":
return AutoLearnConfig
return AutoLearner
if name in ("HypothesisConfig", "HypothesisController", "SynergySearcher"):
from .training.hypothesis_controller import (
HypothesisConfig,
HypothesisController,
SynergySearcher,
)
if name == "HypothesisConfig":
return HypothesisConfig
if name == "HypothesisController":
return HypothesisController
return SynergySearcher
if name in ("generate_with_sampling", "evaluate_perplexity"):
from .inference.inference import generate_with_sampling, evaluate_perplexity
if name == "generate_with_sampling":
return generate_with_sampling
return evaluate_perplexity
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|