Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0! (when checking argument for argument mat2 in method wrapper_CUDA_bmm) #89

Open
mcpaulgeorge opened this issue Aug 5, 2024 · 4 comments

Comments

@mcpaulgeorge
Copy link

The server is three A10s(24 G), I didn't add --multigpu.

@mcpaulgeorge
Copy link
Author

Screenshot 2024-08-05 172010

@shubhra
Copy link

shubhra commented Aug 13, 2024

HItting the same issue with --multigpu and even without it

@SSshuishui
Copy link

SSshuishui commented Sep 3, 2024

Hi, there:
I changed 'LMClass.py' with self.model = AutoModelForCausalLM.from_pretrained(args.model, config=config, device_map='auto',torch_dtype=torch.float16) and self._device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") fixed this problem.
Then change cos, sin = self.rotary_emb(value_states, position_ids=position_ids) query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin) in 'models/int_llama_layer.py'
Finally change cache = {"i": 0, "attention_mask": None} and

class Catcher(nn.Module):
        def __init__(self, module):
            super().__init__()
            self.module = module
            self.is_llama = False
        def forward(self, inp, **kwargs):
            inps[cache["i"]] = inp
            cache["i"] += 1
            # cache["attention_mask"] = kwargs["attention_mask"]
            if self.is_llama:
                cache["position_ids"] = kwargs["position_ids"]
            raise ValueError` 

in quantize/omniquant.py
Hope it can be helpful to you.
My 'transformers' is 4.44.2

@SSshuishui
Copy link

Hi, there: I changed 'LMClass.py' with self.model = AutoModelForCausalLM.from_pretrained(args.model, config=config, device_map='auto',torch_dtype=torch.float16) and self._device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") fixed this problem. Then change cos, sin = self.rotary_emb(value_states, position_ids=position_ids) query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin) in 'models/int_llama_layer.py' Finally change cache = {"i": 0, "attention_mask": None} and

class Catcher(nn.Module):
        def __init__(self, module):
            super().__init__()
            self.module = module
            self.is_llama = False
        def forward(self, inp, **kwargs):
            inps[cache["i"]] = inp
            cache["i"] += 1
            # cache["attention_mask"] = kwargs["attention_mask"]
            if self.is_llama:
                cache["position_ids"] = kwargs["position_ids"]
            raise ValueError` 

in quantize/omniquant.py Hope it can be helpful to you. My 'transformers' is 4.44.2

Not use --multigpu, and change with:

hf_device_map = model.hf_device_map
print(hf_device_map)

for i in range(len(layers)):
    logger.info(f"=== Start quantize layer {i} ===")
    print(f'================={i}==================')
    hf_device = f"cuda:{hf_device_map[f'{layer_name_prefix}.{i}']}"
    layer = layers[i].to(hf_device)
    inps = inps.to(hf_device)
    position_ids = position_ids.to(hf_device)

if don't set # cache["attention_mask"] = kwargs["attention_mask"], has error ValueError: Attention mask should be of size (1, 1, 2048, 2048), but is torch.Size([1, 1, 2048, 2049])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants