Skip to content

Commit

Permalink
ENH: [UI] Support setting CPU when selecting n_gpu (#1096)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengjieLi28 authored Mar 8, 2024
1 parent 45a8625 commit daf5546
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
2 changes: 0 additions & 2 deletions xinference/device_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ def gpu_count():
)

return min(torch.cuda.device_count(), len(cuda_visible_devices))
elif torch.backends.mps.is_available():
return 1
elif is_xpu_available():
return torch.xpu.device_count()
else:
Expand Down
37 changes: 19 additions & 18 deletions xinference/web/ui/src/scenes/launch_model/modelCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ const ModelCard = ({ url, modelData, gpuAvailable, is_custom = false }) => {
}
}, [modelFormat, modelSize, modelData])

const getNGPURange = () => {
if (gpuAvailable === 0) {
// remain 'auto' for distributed situation
return ['auto', 'CPU']
}
return ['auto', 'CPU'].concat(range(1, gpuAvailable))
}

const launchModel = (url) => {
if (isCallingApi || isUpdatingModel) {
return
Expand All @@ -124,7 +132,11 @@ const ModelCard = ({ url, modelData, gpuAvailable, is_custom = false }) => {
model_size_in_billions: convertModelSize(modelSize),
quantization: quantization,
n_gpu:
nGPU === '0' ? null : nGPU === 'auto' ? 'auto' : parseInt(nGPU, 10),
parseInt(nGPU, 10) === 0 || nGPU === 'CPU'
? null
: nGPU === 'auto'
? 'auto'
: parseInt(nGPU, 10),
replica: replica,
}

Expand Down Expand Up @@ -512,24 +524,13 @@ const ModelCard = ({ url, modelData, gpuAvailable, is_custom = false }) => {
onChange={(e) => setNGPU(e.target.value)}
label="N-GPU"
>
{['auto']
.concat(
range(
0,
modelFormat !== 'pytorch' &&
modelFormat !== 'gptq' &&
modelFormat !== 'awq'
? 1
: gpuAvailable
)
{getNGPURange().map((v) => {
return (
<MenuItem key={v} value={v}>
{v}
</MenuItem>
)
.map((v) => {
return (
<MenuItem key={v} value={v}>
{v}
</MenuItem>
)
})}
})}
</Select>
</FormControl>
) : (
Expand Down

0 comments on commit daf5546

Please sign in to comment.