loadJson method
- String json
override
Loads the configuration from a serialized JSON representation.
Implementation
@override
void loadJson(String json) {
final decoded = jsonDecode(json) as Map<String, dynamic>;
final savedKnobs = decoded['knobs'] as Map<String, dynamic>;
const legacyRoles = {
'Query/Key Format': AttentionFormatRole.queryKey,
'Value Format': AttentionFormatRole.value,
'Score Format': AttentionFormatRole.score,
'Normalizer Format': AttentionFormatRole.normalizer,
'Exponential Format': AttentionFormatRole.exponential,
'Reciprocal Format': AttentionFormatRole.reciprocal,
};
if (!savedKnobs.containsKey('Numeric Formats') &&
legacyRoles.keys.any(savedKnobs.containsKey)) {
final migrated = AttentionNumericFormatsKnob();
for (final entry in legacyRoles.entries) {
migrated.formatFor(entry.value).loadJson(
savedKnobs.containsKey(entry.key)
? savedKnobs.remove(entry.key) as Map<String, dynamic>
: formatsKnob.formatFor(entry.value).toJson(),
);
}
savedKnobs['Numeric Formats'] = migrated.toJson();
super.loadJson(jsonEncode(decoded));
} else {
super.loadJson(json);
}
}