minseok
๐ Release BioPhys 6.0 Grand Master: 16GB (14.89GB) Gemma-4 100% Devour, Ecosystem Evolution, Solar MoE, SNN Autoregressive SDK, Dynamic PhaseVM
be99550 | // ๐ [BioPhys 5.0 ํํค์จ ํฌ๊ธฐ์ ๋์ฝ๋ฉ ์์ง] (src/tachyon_speculative.rs) | |
| // ์ํ 1AU ๋๋ํํธ ๋ชจ๋ธ์ด ๋ฏธ๋ K๊ฐ ํ ํฐ์ ๋์ ์์ธกํ๊ณ , 16GB ์ฃผ ๋ชจ๋ธ์ด 1ํ ๋ฐฐ์น๋ก ๋์ ๊ฒ์ฆํ์ฌ ์๋ 3๋ฐฐ ๊ฐ์ | |
| use crate::token_autoregressive_snn::SpikingTokenEngine; | |
| use std::time::Instant; | |
| pub struct TachyonSpeculativeEngine { | |
| pub draft_engine: SpikingTokenEngine, // ์ด๊ณ ์ ์ํ ๋๋ํํธ ๋ชจ๋ธ (1AU) | |
| pub lookahead_k: usize, // ๋์ ์์ธก ๋ฏธ๋ ํ ํฐ ์ (K = 4) | |
| pub total_speculated: usize, | |
| pub total_accepted: usize, | |
| } | |
| impl TachyonSpeculativeEngine { | |
| pub fn new(draft_hidden_dim: usize, lookahead_k: usize) -> Self { | |
| TachyonSpeculativeEngine { | |
| draft_engine: SpikingTokenEngine::new(draft_hidden_dim), | |
| lookahead_k, | |
| total_speculated: 0, | |
| total_accepted: 0, | |
| } | |
| } | |
| /// [ํํค์จ ํฌ๊ธฐ์ ๋์ฝ๋ฉ: K๊ฐ ๋ฏธ๋ ํ ํฐ ๋์ ์์ฑ ๋ฐ ๋จ์ผ ๋ฐฐ์น ๊ฒ์ฆ] | |
| pub fn speculate_and_verify( | |
| &mut self, | |
| current_prompt: &[&str], | |
| target_engine: &mut SpikingTokenEngine, | |
| lattice_energy: f32, | |
| ) -> Vec<String> { | |
| let mut accepted_tokens = Vec::new(); | |
| // 1. ๋๋ํํธ ๋ชจ๋ธ์ด ์ด๊ณ ์์ผ๋ก ๋ฏธ๋ K๊ฐ ํ๋ณด ํ ํฐ ์์ธก (Tachyon Draft) | |
| let mut draft_candidates = Vec::new(); | |
| let mut temp_prompt = current_prompt.to_vec(); | |
| for _ in 0..self.lookahead_k { | |
| let last_token_id = temp_prompt.last() | |
| .and_then(|&w| self.draft_engine.vocab_to_id.get(w).copied()) | |
| .unwrap_or(0); | |
| let logits = self.draft_engine.step_token(last_token_id, lattice_energy); | |
| let mut best_id = 3; | |
| let mut best_l = f32::NEG_INFINITY; | |
| for (id, &l) in logits.iter().enumerate() { | |
| if id > 2 && l > best_l { | |
| best_l = l; | |
| best_id = id; | |
| } | |
| } | |
| let word = self.draft_engine.vocab[best_id].clone(); | |
| draft_candidates.push((best_id, word)); | |
| self.total_speculated += 1; | |
| } | |
| // 2. 16GB ํ๊ฒ ๋ชจ๋ธ์ด 1ํ ๋ฐฐ์น๋ก ํ๋ณด ํ ํฐ๋ค์ ๋์ ๊ฒ์ฆ (Target Verification) | |
| for (cand_id, cand_word) in draft_candidates { | |
| let target_logits = target_engine.step_token(cand_id, lattice_energy); | |
| // ํ๊ฒ ๋ชจ๋ธ์ Top-10 ํ๋ณด์ ๋๋ํํธ ํ ํฐ์ด ํฌํจ๋๋ฉด ํต๊ณผ (Accept) | |
| let mut is_accepted = false; | |
| let mut top_indices: Vec<usize> = (0..target_logits.len()).collect(); | |
| top_indices.sort_by(|&a, &b| target_logits[b].partial_cmp(&target_logits[a]).unwrap()); | |
| if top_indices[0..5.min(top_indices.len())].contains(&cand_id) { | |
| is_accepted = true; | |
| } | |
| if is_accepted { | |
| accepted_tokens.push(cand_word); | |
| self.total_accepted += 1; | |
| } else { | |
| // ๋ถ์ผ์น ์ ํฌ๊ธฐ์ ๋ถ๊ธฐ ์ค๋จ (Fallback) | |
| break; | |
| } | |
| } | |
| if accepted_tokens.is_empty() && !self.draft_engine.vocab.is_empty() { | |
| accepted_tokens.push(self.draft_engine.vocab[3].clone()); | |
| } | |
| accepted_tokens | |
| } | |
| /// ํฌ๊ธฐ์ ์์ฉ๋ฅ (Acceptance Rate) | |
| pub fn acceptance_rate(&self) -> f32 { | |
| if self.total_speculated == 0 { 1.0 } else { (self.total_accepted as f32) / (self.total_speculated as f32) } | |
| } | |
| } | |