core\__init__.py查看源码
core 子包的包标记文件,无实际代码。core 包收录 vLLM-Ascend 定制调度器族:批任务感知调度、DyntraLB 负载均衡调度、重计算调度、短请求优先调度、profiling 动态 chunk 预测,以及 NPU 专属 KV cache 规格定义。
类: 无
core\batch_job_aware_scheduler.py查看源码
面向离线/批量推理的批任务感知调度器(685 行)。核心思想:同一批任务(job)的请求被归入同一桶(RequestBucket,按 prefill 长度最佳适配 O(log n) 查找),调度时用 EWMA 估计每个 job 的 decode 长度(JobDecodeEstimator),并由 RunningBlockReserver 预测下一轮 running 循环的 KV 块需求,据此决定准入预算。主要类:JobNameParser(作业名解析缓存)、JobDecodeEstimator(decode 长度 EWMA 预测)、RunningBlockReserver(KV 块需求预留)、RequestBucket(按 prefill 长度分桶)、BatchJobAwareRequestQueue(作业分组排序 + 预留感知准入的请求队列)、BatchJobAwareScheduler/BatchJobAwareAsyncScheduler(调度器本体及异步变体)。_sort_jobs 按准入预算决定长任务/短任务谁优先。
类: BatchJobAwareRequestQueue, BatchJobAwareScheduler, BatchJobAwareAsyncScheduler
func__init__[17行] 初始化类实例(绑定配置、参数、模块)
funcparse[9行] 从 request_id 解析 #job_name[NAME]# 前缀
funcremove[21行] 从缓存移除一个 request_id
funcclear[3行] 清空全部缓存
funcpredict[19行] 基于 EWMA 预测下一轮该 job 的 decode token 数
funcobserve[31行] 观测真实 decode 长度,更新 EWMA
funcget_stats[9行] 返回该 job 的统计信息
func_cdiv[3行] 整数上除法
funcinvalidate_cache[3行] 失效 best-fit 缓存
func_finalize_reserve[5行] 完成保留块计数
func_compute_one[44行] 为单个请求计算所需 KV 块数
func_compute_all[2行] 为请求列表汇总所需 KV 块数
funcput[13行] 将请求插入等待队列
funcpeek_best_fit_request[19行] 取出 KV 容量最匹配的请求
funcis_empty[3行] 返回队列是否为空
func__len__[2行] 返回队列长度
func__bool__[2行] 返回队列是否非空
func__iter__[3行] 迭代队列
funcadd_request[10行] 添加新请求到队列
funcprepend_request[2行] 将请求插到队列头部(优先调度)
funcprepend_requests[3行] 批量将请求插到队列头部(优先调度)
funcremove_request[21行] Remove a specific request from the queue.
funcremove_requests[3行] 批量移除多个请求
funcpeek_request[8行] 查看队首请求但不移除
funcpop_request[7行] 弹出队首请求
func_get_job_name[2行] 取得请求的 job 名称
func_track_cold_start_req[12行] Track a request as a cold-start request if applicable.
func_get_or_create_job_bucket[12行] Get or create a RequestBucket for a job.
func_free_blocks[2行] 释放请求占用的 KV block
func_admission_budget[6行] Calculate admission budget in tokens.
func_find_admittable[23行] Return the highest‑priority admittable request, or ``None``.
func_get_cold_start_request[10行] Try to get a cold-start request with highest priority.
func_collect_job_decode_info[18行] Collect job decode length information.
func_try_schedule_by_available_tokens[21行] Schedule requests based on job decode length.
func_sort_jobs[15行]
funcschedule[11行] Override to invalidate the block-reserve cache before each step.
func_free_request[7行] Observe the decode length for naturally stopped requests.
core\dyntra_lb_scheduler.py查看源码
DyntraLB 动态负载均衡调度器(1205 行)。用于多实例间按 KV cache 块数均衡负载:模块级函数提供块数估算(get_dyntra_lb_request_block_num)、诊断开关与调度摘要打印;DyntraLBPolicyMixin 是核心,实现完整请求生命周期策略——按调度顺序归并等待队列、阻塞请求提升、KV 远端预取(_run_lb_kv_prefetch,限制预取数为 2×running−len(running))、迁入迁出块的应用(_apply_load_balance_modifications,freeze 时只出不进)、准入控制、被暂停请求的陈旧输出处理与多版本 vLLM 兼容层。DyntraLBScheduler 与 AsyncDyntraLBScheduler 把该 mixin 组合到标准调度器上。
类: DyntraLBPolicyMixin, DyntraLBScheduler, AsyncDyntraLBScheduler
funcget_dyntra_lb_block_size[6行] 返回 DyntraLB 负载均衡用的 KV 块大小
funcget_dyntra_lb_request_block_num[4行] 估算单个请求占用的 KV 块数
funcdiagnostics_enabled[15行] 读 additional_config 中的诊断开关
funcprint_scheduler_summary[41行] 打印调度器当前状态摘要
funcis_schedulable_waiting[2行] 判断请求是否处于可调度等待态
func__init__[18行] 初始化类实例(绑定配置、参数、模块)
func_waiting_requests_in_schedule_order[18行]
func_refresh_blocked_waiting_requests[4行]
func_run_lb_kv_prefetch[66行]
funcprepare_dyntra_lb_step[11行] Prepare requests for the next cross-rank load-balancing decision.
func_apply_load_balance_modifications[40行]
funcreq_blk_num[2行] 计算请求占用的 KV 块数
func_can_admit_waiting_request[2行]
func_scheduler_output_supports[3行]
func_has_pending_deliverable_output[8行]
func_get_connector_computed_blocks[42行]
func_record_prefix_cache_stats[12行]
func_preempt_request[17行]
func_lb_pause_request[14行] Pause a request for DyntraLB load balancing without freeing KV.
func_handle_stopped_request[6行]
func_update_after_schedule[7行]
func_free_request[7行]
funcschedule[778行] 调度入口
core\kv_cache_interface.py查看源码
NPU 专属 KV cache 规格定义(242 行)。为 MLA 类模型扩展 vLLM 的 AttentionSpec:AscendMLAAttentionSpec 携带 Ascend 特有布局元数据(scale_dim/scale_dtype/sparse C8/host 存储/alignment),并实现真实页大小计算(storage_block_size×heads×(head_size+scale))与 DCP 分片下的最大内存估算;AscendSFAIndexerCacheSpec 为 SFA indexer 的 K/scale 缓存定义页大小;AscendSlidingWindowMLASpec 支持滑窗注意力以 MLA 格式存 KV。register_ascend_kv_cache_specs 把这些规格注册进 vLLM,get_storage_block_size 返回一个调度块对应的物理 token 行数。
类: AscendMLAAttentionSpec, AscendSFAIndexerCacheSpec, AscendSlidingWindowMLASpec
funcget_storage_block_size[9行] 返回 KV cache spec 的物理存储块大小
funcstorage_block_size[3行] Return the physical block size consumed by Ascend kernels.
funcreal_page_size_bytes[2行]
funcunpadded_page_size_bytes[2行]
funcmerge[29行]
funcmax_memory_usage_bytes[8行]
funcpage_size_bytes[2行]
func__post_init__[2行] dataclass 后置初始化(计算派生字段)
funcregister_ascend_kv_cache_specs[16行] 注册 Ascend 自定义 KV cache spec
core\profiling_chunk_predictor.py查看源码
基于 profiling 的动态 chunk 大小预测器(465 行)。用二次延迟模型(a·len²+b·len+c)拟合 seq_len→执行耗时,从而在时延目标(target_latency)约束下动态决定每步调度的 token 数。ChunkSizePredictor 负责拟合与预测(支持带历史数据);ProfilingChunkManager 管理整体生命周期:预热 profiling、判断就绪(is_ready/history_ready)、预测 chunk 大小、记录批次实测耗时反哺模型;模块级三个函数在调度与执行两端打点计时并把实测时间附着到输出上。
类: 无
func_start_profiling_chunk_timing[10行] 开始计时一次 chunked prefill 的 profiling
func_finish_profiling_chunk_timing[9行] 结束计时并返回耗时(毫秒)
func_attach_profiling_chunk_execution_time[17行] 把耗时附加到 model runner output
func__init__[20行] 初始化类实例(绑定配置、参数、模块)
funcfit[51行] Fit quadratic coefficients f(l) = al^2 + bl + c from data points.
funcfit_chunk[47行] Fit time with chunks: f(C,H) = a*C(C+H) + b*C + c*H.
funcset_target_latency[18行] Set target latency based on base chunk size.
funcf[2行]
funcget_time[11行] Get time T based on current seq_lens, f(l) = al^2 + bl + c, f(L+x) - f(L) = T
funcget_time_with_history[11行] Get time T based on current seq_lens, f(C,H) = a*C(C+H) + b*(C+H) + c = T
funcpredict[60行] Predict next chunk size x such that f(L+x) - f(L) = target_latency.
funcpredict_with_history[64行] Predict next chunk size x using the history-aware model
funcis_ready[2行]
funchistory_ready[2行]
funcpredict_chunk_size[15行] Predict optimal chunk size for given history length.
funcpredict_time[10行] Get the consumed time of scheduled reqs for time_budget.
funcrecord_batch_execution_time[21行] Record batch execution time for online model refinement.
core\recompute_scheduler.py查看源码
重计算调度器(1426 行,core 包最大的文件)。解决抢占请求恢复问题:被抢占的请求不重新排队,而是按前缀缓存命中情况重算缺失部分。RecomputeScheduler.schedule 在标准调度流程上叠加:connector 前缀命中查询(含 hybrid/Mamba 多组特判与块钳制截断)、重计算请求信息维护(RecomputeReqInfo)、重计算完成的请求把输出补回(_add_recomputed_outputs)。数据类 RecomputeSchedulerConfig/PreemptedRequestData/RecomputeSchedulerOutput 支撑流程;AsyncRecomputeScheduler、DyntraLBRecomputeScheduler、AsyncDyntraLBRecomputeScheduler 通过多重继承组合异步调度与 DyntraLB 负载均衡。
类: RecomputeSchedulerConfig, RecomputeSchedulerOutput, RecomputeScheduler, AsyncRecomputeScheduler, DyntraLBRecomputeScheduler, AsyncDyntraLBRecomputeScheduler
funcinitialize_from_config[14行]
func_get_computed_blocks_for_connector[37行]
func_truncate_computed_blocks_for_connector[18行]
func_truncate_computed_blocks_with_mamba_clamp[21行]
func_apply_load_balance_modifications[3行] Apply optional scheduling-policy changes before running requests.
func_can_admit_waiting_request[3行] Return whether an optional policy allows this waiting request.
func_update_waiting_for_remote_kv[25行] KV Connector: update request state after async recv is finished.
func_finish_recomputed_request[18行] Finish a fallback-recomputed request through the normal abort path.
funcschedule[807行] 调度入口
func_build_kv_connector_meta[4行]
func_add_recomputed_outputs[19行] Add terminal outputs for requests that must retry on prefill.
funcupdate_from_output[337行] 根据 ModelRunnerOutput 更新调度器状态
func__init__[2行] 初始化类实例(绑定配置、参数、模块)
core\scheduler_profiling_chunk.py查看源码
ProfilingChunkScheduler(760 行):把 profiling 动态 chunk 大小接入标准调度循环的调度器子类。初始化时做 profiling chunk 预热(run_profiling_chunk_init),schedule() 中把预测器给出的时延目标换算成时间预算叠加到 token 预算上,先调度 running 请求再处理等待队列;RPC 参数构建与延迟提取辅助方法用于把实测耗时回传预测器。
类: ProfilingChunkScheduler
func__init__[47行] 初始化类实例(绑定配置、参数、模块)
funcrun_profiling_chunk_init[93行] Profile prefill latency using real model forward passes.
func_build_rpc_kwargs[18行] Build kwargs for collective_rpc, handling PP unique_reply_rank.
func_extract_latency[7行] Extract latency value from collective_rpc result.
funcschedule[520行]
core\short_request_first_scheduler.py查看源码
短请求优先(SRF)等待队列策略(384 行)。ShortRequestFirstRequestQueue 维护三条泳道:immediate(谓词命中,如恢复请求)、short(prompt≤阈值)、long;调度时 immediate 最优先,long 队首等待超过 long_max_wait 可越过 short 防饿死(带老化提升统计与退化告警:连续提升老 long 请求会触发一次性 warning)。is_recovery_request 判断恢复请求是否必须插队;install_short_request_first_waiting_queue 把 SRF 队列装到 FCFS 调度器上;ShortRequestFirstAsyncScheduler 为异步变体。
类: ShortRequestFirstRequestQueue, ShortRequestFirstAsyncScheduler
func__init__[12行] 初始化类实例(绑定配置、参数、模块)
func_queues[2行]
func_debug_logging_enabled[2行]
func_queue_name[8行]
func_maybe_log_stats[20行]
func_debug_state[25行]
funcnum_immediate_requests[2行]
funcnum_short_requests[2行]
funcnum_long_requests[2行]
func_classify_queue[6行]
func_long_head_wait_ms[8行]
func_reset_degradation_streak[2行]
func_reset_degradation_streak_if_short_queue_empty[3行]
func_select_schedulable_queue[12行]
func_request_id[2行]
funcadd_request[9行] 添加新请求到队列
funcpop_request[5行] 弹出队首请求
func_maybe_warn_degradation[8行]
func_pop_request_from_queue[23行]
funcpeek_request[8行] 查看队首请求但不移除
funcprepend_request[10行] 将请求插到队列头部(优先调度)
funcprepend_requests[4行] 批量将请求插到队列头部(优先调度)
funcremove_request[11行] 移除指定请求
funcremove_requests[21行] 批量移除多个请求
func__bool__[2行] 返回队列是否非空
func__len__[2行] 返回队列长度
func__iter__[4行] 迭代队列
func__contains__[3行]
func_clear_pin[3行]
func_get_pinned_queue[12行]
funcis_recovery_request[7行] Return whether a request must resume ahead of fresh waiting work.
funcinstall_short_request_first_waiting_queue[30行] Install the SRF queue on a newly constructed FCFS scheduler.
首页