Skip to content

Question about loading qwen3 model #4

@shiwanghua

Description

@shiwanghua
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 14
     12 # model_name = "mistralai/Mistral-7B-v0.3"
     13 model_name = "/home/ubisec/swh/models/deepseek-ai-DeepSeek-R1-0528-Qwen3-8B"
---> 14 model, tokenizer, lm_head = load_model_and_tokenizer(model_name, type = "curlora")

File ~/swh/codes/swh-curlora/code/utils.py:92, in load_model_and_tokenizer(model_name, type)
     90     replace_linear_with_lora(model, rank=16, alpha=1)
     91 else:
---> 92     replace_linear_with_curlora(model, rank=16, alpha=1)
     94 total_params = sum(p.numel() for p in model.parameters() if p.requires_grad)
     95 print(f"Total trainable parameters after: {total_params:,}")

File ~/swh/codes/swh-curlora/code/utils.py:65, in replace_linear_with_curlora(model, rank, alpha)
     63     setattr(model, name, LinearWithCURLoRA(module, rank, alpha))
     64 else:
---> 65     replace_linear_with_curlora(module, rank, alpha)

File ~/swh/codes/swh-curlora/code/utils.py:65, in replace_linear_with_curlora(model, rank, alpha)
     63     setattr(model, name, LinearWithCURLoRA(module, rank, alpha))
     64 else:
---> 65     replace_linear_with_curlora(module, rank, alpha)

    [... skipping similar frames: replace_linear_with_curlora at line 65 (1 times)]

File ~/swh/codes/swh-curlora/code/utils.py:65, in replace_linear_with_curlora(model, rank, alpha)
     63     setattr(model, name, LinearWithCURLoRA(module, rank, alpha))
     64 else:
---> 65     replace_linear_with_curlora(module, rank, alpha)

File ~/swh/codes/swh-curlora/code/utils.py:63, in replace_linear_with_curlora(model, rank, alpha)
     60 for name, module in model.named_children():
     61     #if isinstance(module, torch.nn.Linear):
     62     if any(l in name for l in ["q_proj", "v_proj", "k_proj"]):
---> 63         setattr(model, name, LinearWithCURLoRA(module, rank, alpha))
     64     else:
     65         replace_linear_with_curlora(module, rank, alpha)

File ~/swh/codes/swh-curlora/code/curlora.py:105, in LinearWithCURLoRA.__init__(self, linear, rank, alpha)
    103 super().__init__()
    104 self.linear = linear
--> 105 self.curlora = CURModule(linear.weight, rank)
    106 self.rank = rank
    107 self.alpha = alpha

File ~/swh/codes/swh-curlora/code/curlora.py:63, in CURModule.__init__(self, W, rank)
     61 def __init__(self, W, rank):
     62     super(CURModule, self).__init__()
---> 63     C, U, R = cur_decomposition(W, rank)
     64     self.C = C * 1.0
     65     self.R = R * 1.0

File ~/swh/codes/swh-curlora/code/curlora.py:48, in cur_decomposition(A, c)
     46 r = c
     47 column_probs, row_probs = compute_selection_probabilities(A)
---> 48 selected_columns = select_indices_with_replacement(column_probs, c)
     49 selected_rows = select_indices_with_replacement(row_probs, r)
     51 C = A[:, selected_columns]

File ~/swh/codes/swh-curlora/code/curlora.py:25, in select_indices_with_replacement(probs, k)
     23     probs = probs.cpu().numpy()
     24 else:
---> 25     probs = probs.numpy()
     27 return np.random.choice(len(probs), size=k, replace=True, p=probs)

TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

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