Skip to content

OneFormer-ADE20K-SemSegPreprocessor on MPS - cannot convert a MPS Tensor to float64 dtype #610

@Gabled-Waters

Description

@Gabled-Waters

Trying to use the OneFormer-ADE20K-SemSegPreprocessor or COCO-Segmentor on MPS fails with

"Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead."
I looked into this and AI suggested to pin this to CPU when running on MPS, as I did not want to mess around with the dtypes (no significant impact in overall processing time when I use CPU).

I used a very quick n dirty fix in oneformer.py. I'm not sure if this really fixes the issue as alibaba-pai/Z-Image-Turbo-Fun-Controlnet-Union-2.1 doesn't seem to understand the segmentation map which resulted after this fix, but maybe it's a starting point.

from ..utils import common_annotator_call, define_preprocessor_inputs, INPUT
import comfy.model_management as model_management

class OneFormer_COCO_SemSegPreprocessor:
    @classmethod
    def INPUT_TYPES(s):
        return define_preprocessor_inputs(resolution=INPUT.RESOLUTION())

    RETURN_TYPES = ("IMAGE",)
    FUNCTION = "semantic_segmentate"

    CATEGORY = "ControlNet Preprocessors/Semantic Segmentation"

    def semantic_segmentate(self, image, resolution=512):
        from custom_controlnet_aux.oneformer import OneformerSegmentor

        model = OneformerSegmentor.from_pretrained(filename="150_16_swin_l_oneformer_coco_100ep.pth")

##        original
#        model = model.to(model_management.get_torch_device())

        import torch
        from comfy import model_management
        model = model.to(torch.device("cpu"))

        out = common_annotator_call(model, image, resolution=resolution)
        del model
        return (out,) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions