//! MicroGPT Engine — 数据库原生 GPT 推理+训练引擎 (Phase-68)
//!
//! 基于 Candle ML 框架实现的最小可运行 Decoder-only GPT 模型。
//! 采用标准 Transformer 架构（非 BriLLM SiFu），两者互补共存。
//!
//! ## 功能
//!
//! - **推理**: `MicroGpt::forward()` → logits, `MicroGpt::generate()` → token sequence
//! - **训练**: `MicroGpt::train_step()` → loss + gradient update (AdamW)
//! - **GPU 加速**: 通过 `DeviceSelector` 自动选择 CUDA/Metal/CPU
//!
//! ## Architecture
//!
//! ```text
//! Token IDs ──► wte (Token Embedding)
//!               + wpe (Position Embedding)
//!               ──► TransformerBlock × N
//!                   ├── RMSNorm
//!                   ├── Multi-Head Causal Self-Attention
//!                   ├── Residual + RMSNorm
//!                   └── MLP (expand → GELU → contract)
//!               ──► RMSNorm (final)
//!               ──► LM Head → logits [B, T, vocab_size]
//! ```
//!
//! ## 与 BriLLM SiFu 的关系
//!
//! - MicroGPT (Transformer): 文本生成、语言理解
//! - SiFu (Signal Propagation): 关系推理、知识传播
//! - Phase-71 将通过 Graph-Aware Attention 融合两个引擎

#[cfg(feature = "candle")]
mod engine;

#[cfg(feature = "candle")]
pub mod model_registry;

#[cfg(feature = "candle")]
pub mod auto_trainer;

#[cfg(feature = "candle")]
pub mod graph_attention;

#[cfg(feature = "candle")]
pub use engine::*;

#[cfg(feature = "candle")]
pub use model_registry::ModelRegistry;

// 无 candle 时的桩类型，使 lib.rs 能无条件引用 gpt 模块
#[cfg(not(feature = "candle"))]
mod stub {
    use serde::{Deserialize, Serialize};

    /// GPT 模型配置（无 candle 时仅作数据结构）
    #[derive(Debug, Clone, Serialize, Deserialize)]
    pub struct GptConfig {
        pub vocab_size: usize,
        pub n_embd: usize,
        pub n_head: usize,
        pub n_layer: usize,
        pub block_size: usize,
    }

    impl Default for GptConfig {
        fn default() -> Self {
            Self {
                vocab_size: 256,
                n_embd: 64,
                n_head: 4,
                n_layer: 2,
                block_size: 128,
            }
        }
    }
}

#[cfg(not(feature = "candle"))]
pub use stub::*;
