-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: centralize resource slot type definitions and improve devic…
…e metadata handling in `/react` (#2684) ### TL;DR Added support for dynamic accelerator types and improved resource allocation handling. ### What changed? - Introduced `ResourceSlotName` type to handle known and unknown accelerator types - Updated `ResourceTypeIcon` component to use dynamic resource slot details - Modified `ResourceAllocationFormItems` to use resource slot details for display units - Added JSON schema validation for device metadata - Implemented `isMatchingMaxPerContainer` function for flexible config matching - Updated resource limit calculations to support unknown accelerator types ### The steps to add a new accelerator type 1. Add the accelerator type to `knownAcceleratorResourceSlotNames` in `react/src/hooks/backendai.tsx`. 2. Add an icon for the new accelerator type to `resourceTypeIconSrcMap` in `react/src/components/ResourceNumber.tsx`. 3. Add new accelerator metadata to `resources/device_metadata.json`. After following only step 1, you got a TypeScript error related to step 2 and Jest test failures related to step 3. ### How to test? 1. Run the JSON schema validation test for device metadata 2. Test the resource allocation form with various accelerator types 3. Verify that unknown accelerator types are handled correctly in the UI 4. Check if the resource limits are calculated correctly for all accelerator types ### Why make this change? This change improves the flexibility and maintainability of the codebase by: 1. Supporting dynamic accelerator types without hardcoding 2. Ensuring consistency between device metadata and code 3. Improving resource limit calculations for various accelerator types 4. Enhancing the user interface to display correct units for different accelerators These improvements allow for easier addition of new accelerator types and better handling of resource allocation across different devices.
- Loading branch information
Showing
12 changed files
with
218 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// import json | ||
import deviceMetadata from '../../../resources/device_metadata.json'; | ||
import schema from '../../../resources/device_metadata.schema.json'; | ||
import { | ||
knownAcceleratorResourceSlotNames, | ||
baseResourceSlotNames, | ||
} from './backendai'; | ||
import Ajv from 'ajv'; | ||
import _ from 'lodash'; | ||
|
||
const ajv = new Ajv(); | ||
|
||
describe('deviceMetadata JSON Schema Validation', () => { | ||
it('should include all known accelerator names and base resource names', () => { | ||
const strictSchema = _.cloneDeep(schema); | ||
|
||
// @ts-ignore | ||
strictSchema.properties.deviceInfo.required = [ | ||
...knownAcceleratorResourceSlotNames, | ||
...baseResourceSlotNames, | ||
]; | ||
|
||
const validate = ajv.compile(strictSchema); | ||
const valid = validate(deviceMetadata); | ||
if (!valid) { | ||
console.error(validate.errors); | ||
} | ||
expect(valid).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.