-
Notifications
You must be signed in to change notification settings - Fork 381
Expand file tree
/
Copy pathRuntimeConfiguration.swift
More file actions
72 lines (64 loc) · 2.72 KB
/
Copy pathRuntimeConfiguration.swift
File metadata and controls
72 lines (64 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
public enum RuntimeHeadPath: String, Codable, Sendable {
case fusedRows = "fused-rows"
case logits
}
public enum RuntimePrefillPolicy: String, Codable, Sendable {
case off
case chunked
}
public enum RuntimePrefillAttentionPath: String, Codable, Sendable {
case causalTiled = "causal-tiled"
case fullTensorOps2DPreferred = "full-tensorops-2d-preferred"
case fullTensorOps2DValidityV2 = "full-tensorops-2d-validity-v2"
}
public enum RuntimeExpertCachePolicy: String, Codable, Sendable {
case lfu
case lru
}
public struct RuntimeConfiguration: Sendable, Equatable {
public static let allowedExpertCacheSlots = [8, 16, 24, 32]
public static let allowedPrefillChunkTokens = PrefillRuntimeConfig.allowedChunkTokens
public static let minimumExpertCacheSlotsForChunkedPrefill = 16
public let expertCacheSlots: Int
public let expertCachePolicy: RuntimeExpertCachePolicy
public let rdadvisePolicy: RDAdvicePolicyMode
public let prefillPolicy: RuntimePrefillPolicy
public let prefillChunkTokens: Int
public let prefillAttentionPath: RuntimePrefillAttentionPath
public let headPath: RuntimeHeadPath
public init(expertCacheSlots: Int = 16,
expertCachePolicy: RuntimeExpertCachePolicy = .lfu,
rdadvisePolicy: RDAdvicePolicyMode = .off,
prefillEnabled: Bool = true,
prefillChunkTokens: Int = 128,
prefillAttentionPath: RuntimePrefillAttentionPath = .fullTensorOps2DPreferred,
forceLogitsHead: Bool = false) {
precondition(Self.allowedExpertCacheSlots.contains(expertCacheSlots),
"unsupported expert-cache slot count")
precondition(Self.allowedPrefillChunkTokens.contains(prefillChunkTokens),
"unsupported prefill chunk size")
self.expertCacheSlots = expertCacheSlots
self.expertCachePolicy = expertCachePolicy
self.rdadvisePolicy = rdadvisePolicy
self.prefillPolicy = prefillEnabled ? .chunked : .off
self.prefillChunkTokens = prefillChunkTokens
self.prefillAttentionPath = prefillAttentionPath
self.headPath = forceLogitsHead ? .logits : .fusedRows
}
public static var production: RuntimeConfiguration {
RuntimeConfiguration()
}
public var fp16RingEnabled: Bool { true }
public var rdadviseEnabled: Bool { rdadvisePolicy != .off }
public var prefillConfig: PrefillRuntimeConfig {
switch prefillPolicy {
case .off:
return .off
case .chunked:
return .production(chunkTokens: prefillChunkTokens)
}
}
public var modelExpertCachePolicy: ExpertCachePolicy {
expertCachePolicy == .lru ? .lru : .lfu
}
}