multimodalart HF Staff commited on
Commit
c070a97
·
verified ·
1 Parent(s): afa40de

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +3 -5
app.py CHANGED
@@ -41,7 +41,7 @@ _lora_path = hf_hub_download(CMO_LORA, "adapter_model.safetensors", repo_type="m
41
  _lora_a_pairs = {} # module_path -> A weight (numpy)
42
  _lora_b_pairs = {} # module_path -> B weight (numpy)
43
 
44
- with safe_open(_lora_path, framework="numpy", device="cpu") as _f:
45
  for _key in _f.keys():
46
  if not _key.startswith("base_model.model."):
47
  continue
@@ -55,17 +55,15 @@ with safe_open(_lora_path, framework="numpy", device="cpu") as _f:
55
 
56
  # Merge LoRA weights into the transformer: w_new = w_orig + scale * (B @ A)
57
  _merge_count = 0
58
- for _module_path, _a_np in _lora_a_pairs.items():
59
  if _module_path not in _lora_b_pairs:
60
  continue
61
- _b_np = _lora_b_pairs[_module_path]
62
  # Navigate to the module in the transformer
63
  _module = pipe.transformer
64
  for _part in _module_path.split("."):
65
  _module = getattr(_module, _part)
66
  # Merge: w_orig + scale * (B @ A)
67
- _a_tensor = torch.from_numpy(_a_np)
68
- _b_tensor = torch.from_numpy(_b_np)
69
  _delta = (_b_tensor.float() @ _a_tensor.float()) * LORA_SCALE
70
  _module.weight.data.add_(_delta.to(_module.weight.data.dtype))
71
  _merge_count += 1
 
41
  _lora_a_pairs = {} # module_path -> A weight (numpy)
42
  _lora_b_pairs = {} # module_path -> B weight (numpy)
43
 
44
+ with safe_open(_lora_path, framework="pt", device="cpu") as _f:
45
  for _key in _f.keys():
46
  if not _key.startswith("base_model.model."):
47
  continue
 
55
 
56
  # Merge LoRA weights into the transformer: w_new = w_orig + scale * (B @ A)
57
  _merge_count = 0
58
+ for _module_path, _a_tensor in _lora_a_pairs.items():
59
  if _module_path not in _lora_b_pairs:
60
  continue
61
+ _b_tensor = _lora_b_pairs[_module_path]
62
  # Navigate to the module in the transformer
63
  _module = pipe.transformer
64
  for _part in _module_path.split("."):
65
  _module = getattr(_module, _part)
66
  # Merge: w_orig + scale * (B @ A)
 
 
67
  _delta = (_b_tensor.float() @ _a_tensor.float()) * LORA_SCALE
68
  _module.weight.data.add_(_delta.to(_module.weight.data.dtype))
69
  _merge_count += 1