|
| 1 | +package scheduling |
| 2 | + |
| 3 | +const ( |
| 4 | + FilterCriticalRequestName = "critical_request" |
| 5 | + FilterLeastQueuingName = "least_queuing" |
| 6 | + FilterLowCostLoraName = "low_cost_lora" |
| 7 | + FilterLowLatencyName = "low_latency" |
| 8 | + FilterAffinityLoraName = "affinity_lora" |
| 9 | + FilterSheddableRequestName = "sheddable_request" |
| 10 | + FilterLeastKvCacheName = "least_kv_cache" |
| 11 | + FilterDropRequestName = "drop_request" |
| 12 | + FilterCanAcceptNewLoraName = "can_accept_new_lora" |
| 13 | +) |
| 14 | + |
| 15 | +const ( |
| 16 | + TopKByWaitingQueueSize = "waiting_queue_size" |
| 17 | + TopKByKVCacheUsagePercent = "kv_cache_usage_percent" |
| 18 | +) |
| 19 | + |
| 20 | +var filterMap = map[string]FilterGen{ |
| 21 | + FilterLowLatencyName: FilterLowLatency, |
| 22 | + FilterCriticalRequestName: FilterCriticalRequest, |
| 23 | + FilterLeastQueuingName: FilterLeastQueuing, |
| 24 | + FilterCanAcceptNewLoraName: FilterCanAcceptNewLora, |
| 25 | + FilterSheddableRequestName: FilterSheddableRequest, |
| 26 | + FilterDropRequestName: FilterDropRequest, |
| 27 | + FilterAffinityLoraName: FilterAffinityLora, |
| 28 | + FilterLowCostLoraName: FilterLowCostLora, |
| 29 | + FilterLeastKvCacheName: FilterLeastKvCache, |
| 30 | +} |
| 31 | + |
| 32 | +// FilterGen generate a filter from a filter option |
| 33 | +type FilterGen interface { |
| 34 | + Name() string |
| 35 | + Get(*FilterOption) filter |
| 36 | + Validate(*FilterOption) error |
| 37 | +} |
| 38 | + |
| 39 | +type FilterOption struct { |
| 40 | + KvCacheThreshold *float64 `json:"kvCacheThreshold,omitempty"` |
| 41 | + |
| 42 | + QueueThresholdCritical *int `json:"queueThresholdCritical,omitempty"` |
| 43 | + QueueingThresholdLoRA *int `json:"queueingThresholdLoRA,omitempty"` |
| 44 | +} |
| 45 | + |
| 46 | +type filterGenImpl struct { |
| 47 | + name string |
| 48 | + getter func(*FilterOption) filter |
| 49 | + validator func(*FilterOption) error |
| 50 | +} |
| 51 | + |
| 52 | +var _ FilterGen = &filterGenImpl{} |
| 53 | + |
| 54 | +func (fg *filterGenImpl) Name() string { |
| 55 | + return fg.name |
| 56 | +} |
| 57 | + |
| 58 | +func (fg *filterGenImpl) Get(fo *FilterOption) filter { |
| 59 | + return fg.getter(fo) |
| 60 | +} |
| 61 | + |
| 62 | +func (fg *filterGenImpl) Validate(fo *FilterOption) error { |
| 63 | + return fg.validator(fo) |
| 64 | +} |
| 65 | + |
| 66 | +var ( |
| 67 | + FilterCriticalRequest FilterGen = &filterGenImpl{ |
| 68 | + name: FilterCriticalRequestName, |
| 69 | + getter: func(fo *FilterOption) filter { |
| 70 | + return toFilter(criticalRequestPredicate) |
| 71 | + }, |
| 72 | + validator: func(fo *FilterOption) error { return nil }, |
| 73 | + } |
| 74 | + |
| 75 | + FilterLeastQueuing FilterGen = &filterGenImpl{ |
| 76 | + name: FilterLeastQueuingName, |
| 77 | + getter: func(fo *FilterOption) filter { |
| 78 | + return leastQueuingFilterFunc |
| 79 | + }, |
| 80 | + validator: func(fo *FilterOption) error { return nil }, |
| 81 | + } |
| 82 | + |
| 83 | + FilterLowCostLora FilterGen = &filterGenImpl{ |
| 84 | + name: FilterLowCostLoraName, |
| 85 | + getter: func(fo *FilterOption) filter { |
| 86 | + return toFilter(lowLoRACostPredicate) |
| 87 | + }, |
| 88 | + validator: func(fo *FilterOption) error { return nil }, |
| 89 | + } |
| 90 | + |
| 91 | + FilterLowLatency FilterGen = &filterGenImpl{ |
| 92 | + name: FilterLowLatencyName, |
| 93 | + getter: func(fo *FilterOption) filter { |
| 94 | + return toFilter(lowQueueingPodPredicate) |
| 95 | + }, |
| 96 | + validator: func(fo *FilterOption) error { return nil }, |
| 97 | + } |
| 98 | + |
| 99 | + FilterAffinityLora FilterGen = &filterGenImpl{ |
| 100 | + name: FilterAffinityLoraName, |
| 101 | + getter: func(fo *FilterOption) filter { |
| 102 | + return toFilter(loRAAffinityPredicate) |
| 103 | + }, |
| 104 | + validator: func(fo *FilterOption) error { return nil }, |
| 105 | + } |
| 106 | + |
| 107 | + FilterSheddableRequest FilterGen = &filterGenImpl{ |
| 108 | + name: FilterSheddableRequestName, |
| 109 | + getter: func(opt *FilterOption) filter { |
| 110 | + qtc, kct := queueThresholdCritical, kvCacheThreshold |
| 111 | + if opt != nil { |
| 112 | + if opt.KvCacheThreshold != nil { |
| 113 | + kct = *opt.KvCacheThreshold |
| 114 | + } |
| 115 | + if opt.QueueThresholdCritical != nil { |
| 116 | + qtc = *opt.QueueThresholdCritical |
| 117 | + } |
| 118 | + } |
| 119 | + return toFilter(noQueueAndLessThanKVCacheThresholdPredicate(qtc, kct)) |
| 120 | + }, |
| 121 | + validator: func(fo *FilterOption) error { return nil }, |
| 122 | + } |
| 123 | + |
| 124 | + FilterLeastKvCache FilterGen = &filterGenImpl{ |
| 125 | + name: FilterLeastKvCacheName, |
| 126 | + getter: func(fo *FilterOption) filter { |
| 127 | + return leastKVCacheFilterFunc |
| 128 | + }, |
| 129 | + validator: func(fo *FilterOption) error { return nil }, |
| 130 | + } |
| 131 | + |
| 132 | + FilterDropRequest FilterGen = &filterGenImpl{ |
| 133 | + name: FilterDropRequestName, |
| 134 | + getter: func(fo *FilterOption) filter { |
| 135 | + return dropRequestFilterFunc |
| 136 | + }, |
| 137 | + validator: func(fo *FilterOption) error { return nil }, |
| 138 | + } |
| 139 | + |
| 140 | + FilterCanAcceptNewLora FilterGen = &filterGenImpl{ |
| 141 | + name: FilterCanAcceptNewLoraName, |
| 142 | + getter: func(fo *FilterOption) filter { |
| 143 | + return toFilter(canAcceptNewLoraPredicate) |
| 144 | + }, |
| 145 | + validator: func(fo *FilterOption) error { return nil }, |
| 146 | + } |
| 147 | +) |
0 commit comments