|
1 | 1 | import { |
2 | | - resolveFrameworkAliasesInString, |
| 2 | + FRAMEWORK_ALIASES, |
| 3 | + FW_REGISTRY, |
| 4 | + resolveFrameworkAlias, |
3 | 5 | resolveFrameworkPartLabel, |
4 | 6 | } from '@semianalysisai/inferencex-constants'; |
5 | 7 |
|
6 | 8 | import { type Precision, MODEL_PREFIX_MAPPING, getPrecisionLabel } from '@/lib/data-mappings'; |
7 | | -import { getFrameworkLabel } from '@/lib/utils'; |
| 9 | +import { getHardwareConfig } from '@/lib/constants'; |
| 10 | +import { getDisplayLabel } from '@/lib/utils'; |
| 11 | + |
| 12 | +const CHANGELOG_FRAMEWORK_KEYS = [ |
| 13 | + ...Object.keys(FW_REGISTRY), |
| 14 | + ...Object.keys(FRAMEWORK_ALIASES), |
| 15 | +].toSorted((a, b) => b.length - a.length); |
| 16 | + |
| 17 | +/** |
| 18 | + * Convert a changelog config key into the canonical hardware key used by chart |
| 19 | + * points and the legend. Agentic config keys append scenario details such as |
| 20 | + * `agentic`, `hicache`, and `pcp` after the serving framework; those are not |
| 21 | + * framework labels and must not become part of the legend identity. |
| 22 | + */ |
| 23 | +export function changelogConfigToHwKey(configKey: string): string | null { |
| 24 | + const parts = configKey.toLowerCase().split('-'); |
| 25 | + const gpu = parts[2]; |
| 26 | + const remainder = parts.slice(3).join('-'); |
| 27 | + if (!gpu || !remainder) return null; |
| 28 | + |
| 29 | + const framework = CHANGELOG_FRAMEWORK_KEYS.find( |
| 30 | + (candidate) => remainder === candidate || remainder.startsWith(`${candidate}-`), |
| 31 | + ); |
| 32 | + if (!framework) return null; |
| 33 | + |
| 34 | + const trailingParts = remainder.slice(framework.length).split('-').filter(Boolean); |
| 35 | + const specSuffix = trailingParts.includes('mtp') ? '_mtp' : ''; |
| 36 | + return `${gpu}_${resolveFrameworkAlias(framework)}${specSuffix}`; |
| 37 | +} |
8 | 38 |
|
9 | 39 | export function formatChangelogDescription(desc: string | string[]) { |
10 | 40 | if (typeof desc === 'string') { |
@@ -33,23 +63,26 @@ export function formatChangelogDescription(desc: string | string[]) { |
33 | 63 | * Normalizes both to hyphen-separated form for comparison. |
34 | 64 | */ |
35 | 65 | export function configKeyMatchesHwKey(configKey: string, hwKey: string): boolean { |
36 | | - const gpuAndFramework = resolveFrameworkAliasesInString(configKey.split('-').slice(2).join('-')); |
37 | | - const normalizedHwKey = hwKey.replaceAll('_', '-'); |
38 | | - return gpuAndFramework === normalizedHwKey; |
| 66 | + return changelogConfigToHwKey(configKey) === hwKey; |
39 | 67 | } |
40 | 68 |
|
41 | 69 | export function formatConfigKeys(key: string) { |
42 | 70 | const parts = key.split('-'); |
43 | 71 | const model = parts[0]; |
44 | 72 | const precision = parts[1]; |
45 | | - const gpu = parts[2]; |
46 | | - const framework = parts.slice(3).join('-'); |
47 | | - // Strip -mtp suffix before lookup; MTP is shown separately |
48 | | - const isMtp = framework.endsWith('-mtp'); |
49 | | - const baseFramework = isMtp ? framework.slice(0, -4) : framework; |
50 | | - const baseLabel = getFrameworkLabel(baseFramework); |
51 | | - // M3's `mtp` spec token renders as "EAGLE"; every other model keeps "MTP". |
52 | | - const mtpLabel = resolveFrameworkPartLabel(MODEL_PREFIX_MAPPING[model], 'mtp'); |
53 | | - const frameworkLabel = isMtp ? `${baseLabel}, ${mtpLabel}` : baseLabel; |
54 | | - return `${gpu.toUpperCase()} (${frameworkLabel}) ${MODEL_PREFIX_MAPPING[model]} ${getPrecisionLabel(precision as Precision)}`; |
| 73 | + const modelLabel = MODEL_PREFIX_MAPPING[model]; |
| 74 | + const hwKey = changelogConfigToHwKey(key); |
| 75 | + |
| 76 | + if (!hwKey) { |
| 77 | + const gpu = parts[2]?.toUpperCase() ?? ''; |
| 78 | + const framework = parts.slice(3).join('-'); |
| 79 | + const frameworkLabel = resolveFrameworkPartLabel(modelLabel, framework); |
| 80 | + return `${gpu} (${frameworkLabel}) ${modelLabel} ${getPrecisionLabel(precision as Precision)}`; |
| 81 | + } |
| 82 | + |
| 83 | + // Use the same hardware entry builder and display combiner as the legend so |
| 84 | + // aliases, compound framework names, and model-specific spec labels cannot |
| 85 | + // drift between the two surfaces. |
| 86 | + const hardwareLabel = getDisplayLabel(getHardwareConfig(hwKey, modelLabel)); |
| 87 | + return `${hardwareLabel} ${modelLabel} ${getPrecisionLabel(precision as Precision)}`; |
55 | 88 | } |
0 commit comments