每日练习与编程练习

← 返回日报
任务 第一则

证据路由与采样优化

任务 94/100

你在做一个“长视频问答/会议检索”服务。每个请求是一条自然语言任务,底层索引里有百万级 5~10 秒视频片段、ASR 文本、片段摘要,以及少量人工标注的主张级证据。系统要求 p95 延迟不超过 300ms,且单请求最多只能做 1 次 GPU 重批处理;完整视频特征提取一次约 12ms,摘要召回约 1ms,主张级文本检索约 3ms,但如果一次拉太多候选,后续多模态推理会明显涨显存并拖慢尾延迟。

请设计一个在线路由与采样方法:输入 query 后,系统如何在“只看摘要/ASR、检索主张、拉取完整视频特征、提前停止或继续扩展”之间做决策?要求说明你的打分建模、预算控制、停止条件、如何处理证据分散在多个片段中的情况、如何避免选到相邻冗余片段,以及如何保证离线评估和线上效果尽量一致。

参考回答

我会把它建模成一个“预算约束下的自适应证据选择”任务,而不是一次性 top-k 检索。核心目标不是单纯最大化相似度,而是在时延预算内最大化“答案正确率/证据召回”的期望收益。

第一步是做粗召回。对 query 先用轻量编码器分别检索视频摘要、ASR 文本和主张库,得到候选集合 C。对每个候选 i 计算一个便宜的置信分数 s_i 和不确定性 u_i;如果能估计到候选的边际增益,最好再估一个 g_i = P(该候选能新增有效证据 | q, cheap features)。这里不要直接相信 raw score,必须做校准,比如 temperature scaling / isotonic regression,否则阈值会在不同领域漂。

第二步是做分层路由。把候选按时间轴或场景切成 bucket,先在每个 bucket 里取 1 个代表,避免相邻冗余。然后用一个带预算的贪心/优先队列策略,反复选择单位成本边际收益最高的候选: - 优先级可以写成 `priority_i = (g_i + λ * u_i) / cost_i`; - 若候选之间有重叠语义,就加一个冗余惩罚项,比如和已选集合的最大相似度或 coverage overlap。 这个形式本质上接近预算约束的子模优化,工程上很适合做“贪心 + 截断”。如果要更稳,可以把每个候选视为一条“证据臂”,用上界分数 `upper_i = s_i + βu_i` 做 best-first 扩展,直到预算耗尽或 top1 与 next-best 的 margin 足够大。

第三步是自适应停止。不要固定拿 K 个候选。更合理的是设置三个停止条件: 1. 证据置信度足够高:top1 分数高且 top1-top2 gap 足够大; 2. 覆盖足够好:已选片段覆盖了 query 的不同子任务/时间范围; 3. 边际收益低于成本:下一次扩展的上界收益低于继续推理的时延代价。 如果三者都不满足,再升级到更贵的完整视频特征或更强重排器。若仍然低置信,则进入 abstain 或澄清任务分支,避免硬答。

训练上我会分两层: - 轻量 router 用监督学习做候选排序,正样本是答案链路中的真证据,负样本用 hard negative 和邻近时间负样本; - 路由阈值和停止策略用离线日志做反事实评估,再在线做小流量校准。 如果有教师模型,可以把“看全量证据后的决策”蒸馏给 router,让 cheap scorer 学到更接近最终答案收益的分布,而不是只学相似度。

复杂度上,粗召回如果用 ANN,大致是 `O(log N + m)`;后续贪心扩展是 `O(M log M)`,M 是实际展开的候选数,远小于全量扫描。显存上,只把被选中的少量候选送入重模型,因此峰值显存和尾延迟都可控。

工程上最关键的取舍有三个: - 召回 vs 延迟:阈值低会涨召回但拖尾延迟; - 冗余 vs 覆盖:只取最高分会错过跨片段证据; - 稳定性 vs 激进:在线分布漂移时要保守路由,必要时降级到文本证据。 最后要监控的不是单一 accuracy,而是 evidence recall、calibration error、p95/p99 latency、以及 abstain 率。这样系统才能在真实流量下稳定工作。

回答分析

强答应该把任务抽象成“预算约束的自适应证据选择/级联路由”,而不是停留在“先召回再重排”的泛泛说法。最重要的是讲清: 1. 如何定义目标函数:答案正确率、证据召回、冗余惩罚、成本约束; 2. 如何做分层决策:粗召回、候选分桶、边际收益驱动扩展、提前停止; 3. 为什么要做校准:否则阈值和 stop policy 在跨域场景会失效; 4. 如何处理分散证据和相邻冗余:时间分桶、coverage、MMR/子模贪心; 5. 如何落地:ANN、批处理、显存上限、尾延迟、abstain 降级、日志反事实评估。

常见错误包括: - 只说 top-k 检索,没有预算控制和停止条件; - 忽略冗余,导致一堆相邻片段占满预算; - 只谈离线指标,不谈在线尾延迟和分布漂移; - 没有校准,阈值只能靠拍脑袋; - 没有说明当证据不足时如何安全失败。

出练习者可能继续追问:如果证据分布极度长尾怎么办、如何证明贪心近似合理、如何做线上 A/B 但不伤主链路、如何在多模态和纯文本候选之间统一打分。

评分
94/100
任务定义 20/20正确性 24/25复杂度 19/20工程取舍 18/20表达 13/15
追问
  • 如果 query 同时涉及多个时间段,你如何把“覆盖率”形式化并加入打分?
  • 如何在不增加太多延迟的情况下做 score calibration 和阈值更新?
  • 线上 A/B 时,如果新路由提升召回但拉高 p99,你会怎么做分流与降级?
类比
像搜索引擎先看摘要再决定是否打开全文,而且每次都要控制翻页成本。

往期记录 146 条记录

2026年08月01日查询引导长视频采样interviewSubmodularKnapsackTemporalCoverage
2026年08月01日边界元素是最大值的子数组数目codeStackArrayMonotonicStack
2026年07月30日受限内存推理调度interviewLLM-servingKV-cacheScheduling
2026年07月29日技能感知词元压缩interviewTokenCompressionMultimodalKnapsack
2026年07月27日递归验证预算分配interviewAStarBanditSubmodular
2026年07月26日推理早停预算分配interviewOptimalStoppingSequentialTestCalibration
2026年07月26日二叉树中所有距离为 K 的结点codeTreeBFSDFS
2026年07月25日流式同传轨迹调度interviewStreamingMonotonicAlignmentLatencyControl
2026年07月25日分割回文串codepalindromebacktrackingdynamicprogramming
2026年07月24日最大节点价值之和codeGreedyBitManipulationTree
2026年07月23日长音视频工具调度interviewTool RoutingDAG SchedulingSubmodular Maximization
2026年07月20日流式多模态记忆检索interviewStreaming MemoryMultimodal RetrievalTemporal Indexing
2026年07月20日T 秒后青蛙的位置codeTreeDFSProbability
2026年07月20日约束预算模型路由interviewModel RoutingConstrained OptimizationContextual Bandit
2026年07月20日匹配模式数组的子数组数目 IIcodeArrayKMPStringMatching
2026年07月20日受限显存解码调度interviewLLMCompilerKVCacheScheduling
2026年07月20日填充每个节点的下一个右侧节点指针 IIcodeTreeBFSLinkedList
2026年07月02日变分信息瓶颈Information BottleneckVariational BoundRate-Distortion
2026年07月01日CTC序列对齐方法CTCForward-Backward MethodBlank Token
2026年07月01日故障流行病学Core DumpStatistical DebuggingFault Localization
2026年06月30日哈希嵌入压缩Hash EmbeddingFeature HashingEmbedding Compression
2026年06月29日一致性蒸馏Consistency ModelsProgressive DistillationODE Trajectory
2026年06月29日原生推理引擎Native RuntimeggmlInference Engine
2026年06月28日无分类器引导Classifier-Free GuidanceGuidance ScaleScore Interpolation
2026年06月25日MVDR波束成形MVDR BeamformingSpatial FilteringCovariance Estimation
2026年06月24日神经缩放定律Scaling LawsCompute-Optimal TrainingPower Law
2026年06月23日最小贝叶斯风险解码Minimum Bayes RiskDecision TheoryHypothesis Selection
2026年06月23日PID控制与生成调控PID ControllerFeedback ControlClosed-loop Generation
2026年06月22日生成模型评估度量Frechet Inception DistanceGenerative EvaluationFeature Statistics
2026年06月21日浮点量化收缩偏差FP4 TrainingShrinkage BiasLow-Precision Arithmetic
2026年06月21日模型上线仿真Deployment SimulationShadow TestingOffline Evaluation
2026年06月20日现代联想记忆Hopfield NetworkAssociative MemoryEnergy-Based Model
2026年06月19日离散扩散语言模型Discrete DiffusionAbsorbing StateConcrete Score
2026年06月18日循环变换器架构Looped TransformerWeight TyingAdaptive Computation
2026年06月17日韵律建模演进Prosody PredictionF0 ModelingDuration Prediction
2026年06月16日说话人日志Speaker DiarizationSpeaker EmbeddingEEND
2026年06月15日偏好对齐优化Preference OptimizationDPOReward Modeling
2026年06月14日多令牌并行预测Multi-Token PredictionSpeculative DecodingParallel Decoding
2026年06月13日流匹配生成模型Flow MatchingRectified FlowOptimal Transport Path
2026年06月13日实时管线延迟预算Latency BudgetPipeline OrchestrationTime-to-First-Token
2026年06月12日MoE路由机制Mixture of ExpertsSparse GatingRouter Design
2026年06月11日连续自回归生成Continuous AutoregressiveLatent PredictionAudioVAE
2026年06月10日KV缓存压缩KV Cache CompressionToken EvictionAttention Sparsity
2026年06月09日浏览器端模型推理WebGPUBrowser InferenceClient-side ML
2026年06月02日残差向量量化Residual Vector QuantizationAudio TokenizationNeural Codec
2026年05月31日彩色噪声扩散采样Colored NoiseSpectral BiasSDE Solver
2026年05月31日算子融合编译原理Kernel FusionOperator Fusiontorch.compile
2026年05月20日AI生成内容溯源 (7 chars) ✓Content ProvenanceC2PASynthID
2026年05月19日推理委托设计模式 (8 chars) ✓ Let me now write the full content for both topics. Actually, I realize I should double-check: is "Runtime Abstraction" or "Delegate Pattern" too close to any covered keyword? Looking at the list: Cluster Scheduling, Co-design, Collective Communication, Computational Expressiveness, CUTLASS... No, none of these overlap. OK, let me finalize and write everything out. Let me reconsider the engineering topic one more time. The title "推理委托设计模式" is good but maybe I should make it even more specific and interesting. What about focusing on the "graph partitioning" aspect - how ML runtimes decide which operations to delegate to which backend? This is a more specific and technically interesting angle. No, I think the broader "delegate pattern" is better because it covers the full picture and is more useful to the reader. Let me write it all out now. For the engineering topic, let me think about the history: - Early days: frameworks were monolithic (Caffe, early TensorFlow) - TensorRT (2017): NVIDIA's specialized inference engine, initially standalone - ONNX Runtime (2019): Microsoft introduced "Execution Providers" - the first major delegate-like abstraction - TFLite delegates (2018-2019): TensorFlow Lite introduced delegate API for GPU, NNAPI, etc. - ExecuTorch (2023-2024): PyTorch's answer to edge inference with a clean delegate API - 2025-2026: MLX delegate, Qualcomm AI Engine Direct delegate, etc. This is a rich history. Let me write it up. Actually, I want to make sure I have the dates right: - TensorRT was first released around 2016-2017 - ONNX was announced in 2017 - ONNX Runtime was open-sourced in 2018-2019 - TFLite was released in 2017, delegates came later - ExecuTorch was announced at PyTorch Conference 2023 OK, let me write everything now. I'll be thorough. One more thought: for the MATH section of the engineering topic, I could discuss the graph partitioning problem formally, or I could discuss the cost model for deciding whether to delegate. Let me think... The graph partitioning for delegation can be formalized as: - Given a computation graph $G = (V, E)$ where $V$ is the set of operations and $E$ is data dependencies - And a set of delegates $D = \{d_1, ..., d_m\}$ where each delegate supports a subset of operations $S_i \subseteq V$ - Find a partition $P = \{P_0, P_1, ..., P_m\}$ (where $P_0$ is the fallback/CPU partition) that minimizes total execution time - Subject to: each $
2026年05月17日连续批处理异步化
2026年05月10日连续潜在扩散语言模型Continuous Latent DiffusionNon-autoregressive LMDiffusion Language Model
2026年05月10日零样本跨语言语音克隆Zero-shot Voice CloningCross-lingual TTSIPA Phoneme Representation
2026年05月09日最优传输音频距离Optimal TransportFréchet Audio DistanceRiemannian Metric
2026年05月09日推荐系统推理核内广播优化Intra-kernel BroadcastEmbedding TableRecommendation Inference
2026年05月08日扩散Transformer异常值令牌Outlier TokensDiffusion TransformerAttention Sink
2026年05月08日WebRTC低延迟语音工程WebRTCReal-time AudioJitter Buffer
2026年05月07日音素级深度伪造检测原理Phoneme-level Deepfake DetectionSelf-supervised Speech EmbeddingEmotional Speech Synthesis
2026年05月07日AI训练网络协议工程哲学Multi-path Reliable ConnectionRDMA over EthernetCollective Communication
2026年05月05日对抗解纠缠说话人验证Speaker DisentanglementAdversarial TrainingCross-lingual Verification
2026年05月05日LLM推理为何用语言Chain-of-ThoughtLatent ReasoningToken Space
2026年05月01日跨架构知识蒸馏原理Cross-Architecture DistillationDiffusion LMAutoregressive Teacher
2026年05月01日AI评估计算瓶颈工程LLM Evaluation InfrastructureBenchmark SaturationEval Compute Bottleneck
2026年04月29日平衡传输语音增强Schrödinger BridgeStochastic Differential EquationSpeech Enhancement
2026年04月29日深度学习理论形成Deep Learning TheoryLoss LandscapeNeural Tangent Kernel
2026年04月28日语义进度函数原理Semantic Progress FunctionDiffusion TrajectoryNonlinear Denoising
2026年04月28日大模型OCR选型认知OCR BenchmarkModel Selection BiasCost-Performance Tradeoff
2026年04月27日说话人验证核心原理Speaker Verificationd-vectorECAPA-TDNN
2026年04月27日GPU核函数语言选型GPU Kernel EngineeringCuTe DSLCUTLASS
2026年04月26日时长控制TTS原理Duration ModelingProsody ControlAutoregressive TTS
2026年04月26日AI研究价值评估困境Research EvaluationPublication BiasPeer Review
2026年04月25日全双工对话建模原理Full-Duplex DialogueTurn-TakingVoice Activity Detection
2026年04月25日流式TTS文本规范化Text NormalizationStreaming TTSInverse Text Normalization
2026年04月24日离散扩散语言模型原理Discrete DiffusionMasked Diffusion Language ModelAbsorbing Diffusion
2026年04月24日跟进ML研究的认知工程Information OverloadResearch TriageSpaced Repetition
2026年04月23日一致性正则化ASR原理Consistency RegularizationUnified ASRTransducer
2026年04月23日流式TTS文本规范化工程Text NormalizationStreaming TTSInverse Text Normalization
2026年04月22日神经编码器伪影检测Neural Audio CodecArtifact DetectionForensic Residual
2026年04月22日AI研究复现危机工程Reproducibility CrisisML EngineeringExperimental Rigor
2026年04月21日扩散SNR偏差校正原理Signal-to-Noise RatioDiffusion Timestep BiasScore Matching
2026年04月21日论文复现危机根治工程Reproducibility CrisisAblation StudyExperimental Rigor
2026年04月20日音频时序定位原理Temporal GroundingAudio Event DetectionCross-modal Alignment
2026年04月20日论文复现危机根因Reproducibility CrisisBenchmark OverfittingEvaluation Validity
2026年04月19日流匹配对齐原理Flow Matching AlignmentReward Gradient BackpropagationTrajectory Optimization
2026年04月19日分布式训练任务编排Distributed Training OrchestrationCluster SchedulingFault Tolerance
2026年04月18日最优传输信号融合Optimal TransportWasserstein BarycenterTime-Frequency Resolution
2026年04月18日分布式训练任务调度Distributed Training OrchestrationJob SchedulingCluster Resource Management
2026年04月17日扩散语音识别原理Masked Diffusion Language ModelDiscrete DiffusionASR Decoding
2026年04月17日Mel尺度跨文化偏差Mel ScalePsychoacousticsCultural Bias
2026年04月16日音频水印对抗原理Audio WatermarkingSemi-FragilePsychoacoustic Masking
2026年04月16日推测解码草稿树工程Speculative DecodingDraft TreeBlock Diffusion
2026年04月15日对抗流模型原理Continuous Normalizing FlowAdversarial TrainingFlow Matching
2026年04月15日代理状态可观测性工程Agent ObservabilityDistributed TracingState Machine Debugging
2026年04月14日过程奖励模型原理Process Reward ModelStep-level SupervisionReasoning Chain
2026年04月13日离散令牌音源分离Discrete Token ModelingSource SeparationConditional Generation
2026年04月13日超算API工程哲学Distributed Training OrchestrationSupercomputer API DesignFault Tolerance
2026年04月12日信息瓶颈原理演进Information BottleneckVariational IBDisentanglement
2026年04月12日Safetensors格式工程哲学SafetensorsModel SerializationMemory-Mapped IO
2026年04月11日归一化层演进原理Layer NormalizationRMS NormalizationBatch Normalization
2026年04月11日GEMM自调优后端工程GEMM AutotuningTorchInductorCuteDSL
2026年04月10日多令牌预测原理Multi-Token PredictionSpeculative DecodingMedusa Heads
2026年04月10日ML从业者认知校准Calibration BiasCapability IllusionBenchmark Overfitting
2026年04月09日编码器-解码器LM原理Encoder-Decoder LMCross-Attention ConditioningSequence-to-Sequence
2026年04月09日torch.compile归一化优化torch.compileLayerNormRMSNorm
2026年04月08日KV缓存压缩原理KV Cache CompressionRoPE Position EncodingAttention Score Estimation
2026年04月08日音效基础模型工程Sound Effect GenerationFoundation ModelFoley Synthesis
2026年04月07日可验证奖励强化学习Verifiable RewardRLVRProcess Reward Model
2026年04月07日LLM技能退化认知机制Cognitive OffloadingSkill AtrophyDesirable Difficulty
2026年04月06日音素可解释说话人验证Phoneme-aware Speaker VerificationInterpretable BiometricsLocal Acoustic Evidence
2026年04月06日音频幻觉攻击评估Hallucination AttackAudio Language Model ReliabilityAdversarial Probing
2026年04月05日潜在空间推理原理Latent Space ReasoningContinuous RepresentationToken-Free Inference
2026年04月05日mRNA模型极低成本训练Biology Foundation ModelCross-Species TransferLow-Budget Training
2026年04月04日编码器-解码器TTS原理Encoder-Decoder TTSText ConditioningPositional Capacity
2026年04月04日大模型训练的MXFP8工程MXFP8MicroscalingMixed Precision Training
2026年04月03日在线知识蒸馏原理Online DistillationKnowledge TransferStudent-Teacher
2026年04月03日MoE专家并行调度工程Expert ParallelismMixture of ExpertsAll-to-All Communication
2026年04月02日波形潜空间扩散TTSwaveform latent diffusionnon-autoregressive TTSlatent space acoustic modeling
2026年04月02日波形隐空间扩散原理waveform latent spacediffusion TTSVAE audio codec
2026年04月02日LLM量化权重工程weight quantizationLLM compression4-bit quantization
2026年04月02日扩散语言模型离散生成Discrete DiffusionMasked Diffusion Language ModelNon-autoregressive TTS
2026年04月02日LLM后训练库工程演进RLHF engineeringPPO training stabilityreward hacking
2026年04月02日声学证据瓶颈原理Audio Evidence BottleneckAcoustic GroundingAudio Language Model
2026年04月02日状态空间模型音频建模State Space ModelMambaSelective Scan
2026年04月02日实时语音增强工程选型Real-time Speech EnhancementNoise SuppressionStreaming Inference
2026年04月02日对话上下文压缩原理Context CompressionAbstractive SummarizationCross-Attention Fusion
2026年04月02日说话人匿名化工程Speaker AnonymizationVoice ConversionStreaming Inference
2026年04月02日视听语音识别融合Audio-Visual Speech RecognitionLip ReadingViseme
2026年04月02日GPU训练吞吐加速工程MXFP8MoE TrainingExpert Parallelism
2026年04月01日熵驱动多样性生成diversity samplingtypicality biasrepulsion in latent space
2026年04月01日说话人分割工程选型speaker diarizationbenchmark methodologystreaming ASR pipeline
2026年03月31日转向检测联合建模turn-taking detectionvoice activity detectionjoint acoustic-linguistic modeling
2026年03月31日基准测试的系统性失效benchmark contaminationevaluation validityLLM judge reliability
2026年03月31日扩散模型声学生成diffusion modelscore matchingstochastic differential equation
2026年03月31日TTS开源生态竞争open-weight TTStime-to-first-audiomultilingual speech synthesis
2026年03月30日注意力机制变体演进Multi-Head AttentionGrouped Query AttentionMulti-head Latent Attention
2026年03月30日设备端语音推理架构on-device inferenceExecuTorchvoice agent pipeline
2026年03月29日混合自回归流匹配TTSautoregressive semantic tokensflow matching acoustic decoderhybrid TTS architecture
2026年03月29日NCCL超时诊断方法论NCCL watchdog timeoutdistributed training debuggingcollective communication
2026年03月29日混合架构音频表示Mambastate space modelaudio representation learning
2026年03月29日DeepSeek预训练加速工程MXFP8 trainingexpert parallelismMoE pretraining
2026年03月27日说话人验证度量学习speaker verificationmetric learningcurriculum learning
2026年03月27日MX浮点格式加速训练MXFP8microscalingmixed precision training
2026年03月26日TTS模型极限压缩model compressionknowledge distillationTTS on-device
2026年03月26日小模型极限压缩哲学model compressionknowledge distillationquantization
2026年03月25日流匹配生成原理flow matchingrectified flowODE
2026年03月25日神经音频编解码器neural audio codecresidual vector quantizationEnCodec
2026年03月25日推测解码加速推理speculative decodingdraft modeltoken verification