Project-MONAI / Project-MONAI/MONAILabel
Allow the use of cpu when having GPUs
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 891
- Forks
- 269
- Avg merge
- 15h 41m
- Merged PRs (30d)
- 1
Description
Describe the solution you'd like
In some cases with large models as total segmentator, or when we have large full body CT running inference can result in OOM errors using gpus. It would be nice to have the ability to pick cpu from device list
we can change the lines of https://github.com/Project-MONAI/MONAILabel/blob/main/monailabel/utils/others/generic.py#L192-L200
to
def device_list():
if torch.cuda.is_available()
devices = []
else:
return ["cpu"]
if torch.cuda.device_count() == 1:
devices.append(torch.cuda.get_device_name(0))
else:
for i in range(torch.cuda.device_count()):
devices.append(f"{torch.cuda.get_device_name(i)}:{i}")
devices.append("cpu") < ------- add cpu in the end
return devices
Describe alternatives you've considered
For now I manaually do that in my init of my infer as
class myNetwork(BasicInferTask):
def __init__(self,path,network,
parameters,
type=InferType.SEGMENTATION,labels=None,dimension=3,
**kwargs,
):
super().__init__(path=path,network=network,type=type,
labels=labels,dimension=dimension,description=description,
**kwargs,)
self._config["device"]= device_list()+["cpu"] ## adding cpu to use
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in monailabel/utils/others/generic.py around lines 192-200 and inspect device_list(). Verify how the returned devices are used by the inference configuration. The change is complete when CPU can be selected alongside available GPUs and remains available when CUDA is unavailable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100