Fix `extra_info()` return type inconsistency in accelerator plugins
- Dominant language
- Python
- Stars
- 670
- Forks
- 183
- Avg merge
- 17h 7m
- Merged PRs (30d)
- 358
Description
## Motivation
The `AbstractComputePlugin.extra_info()` interface method is typed to return `Mapping[str, str]`, but several concrete implementations actually return `Mapping[str, Any]` containing boolean values. This type inconsistency creates potential runtime issues and prevents proper static type checking across the codebase.
For example, accelerator plugins like CUDA, ROCm, and Gaudi return dictionaries containing boolean flags (e.g., `cuda_support: True`, `rocm_support: True`), while the interface contract expects all values to be strings.
## Objective
Align all `extra_info()` method implementations with the declared return type `Mapping[str, str]` by converting boolean values to string representations.
## Details
The following files contain `extra_info()` implementations that return non-string values:
- `src/ai/backend/accelerator/cuda_open/plugin.py` - Returns `{"cuda_support": True/False`}
- `src/ai/backend/accelerator/cuda/plugin.py` - Returns `{"cuda_support": True/False`}
- `src/ai/backend/accelerator/rocm/plugin.py` - Returns `{"rocm_support": True/False`}
- `src/ai/backend/accelerator/gaudi/plugin.py` - Returns `{"gaudi_support": True/False`}
Changes required:
1. Convert boolean return values to lowercase string representations (`"true"` / `"false"`)
1. Update any code that consumes these values to handle string-based boolean parsing if needed
1. Verify no other plugins have similar type mismatches
Example fix:
```python
# Before
def extra_info(self) -> Mapping[str, Any]:
return {"cuda_support": self._cuda_available}
# After
def extra_info(self) -> Mapping[str, str]:
return {"cuda_support": str(self._cuda_available).lower()}
Impact
- GQL Layer: The ComputePluginInfoGQL type can safely use Mapping[str, str] without requiring str() coercion for values
- Agent Registration: AgentRow.compute_plugins data will have consistent string-only values
- Type Safety: Enables proper static type checking for compute plugin metadata throughout the codebase
```
JIRA Issue: BA-3906
Contributor guide
Assessment
This issue has not been assessed yet.