Spaces:
Sleeping
Sleeping
init
Browse files- app.py +22 -46
- packages.txt +0 -0
app.py
CHANGED
@@ -61,18 +61,11 @@ def load(
|
|
61 |
max_batch_size: int,
|
62 |
) -> LLaMA:
|
63 |
start_time = time.time()
|
64 |
-
# checkpoints = sorted(Path(ckpt_dir).glob("*.pth"))
|
65 |
-
# assert world_size == len(
|
66 |
-
# checkpoints
|
67 |
-
# ), f"Loading a checkpoint for MP={len(checkpoints)} but world size is {world_size}"
|
68 |
-
# ckpt_path = checkpoints[local_rank]
|
69 |
print("Loading")
|
70 |
-
# checkpoint = torch.load(ckpt_path, map_location="cuda")
|
71 |
instruct_adapter_checkpoint = torch.load(
|
72 |
instruct_adapter_path, map_location="cpu")
|
73 |
caption_adapter_checkpoint = torch.load(
|
74 |
caption_adapter_path, map_location="cpu")
|
75 |
-
# with open(Path(ckpt_dir) / "params.json", "r") as f:
|
76 |
with open(param_path, "r") as f:
|
77 |
params = json.loads(f.read())
|
78 |
|
@@ -88,22 +81,21 @@ def load(
|
|
88 |
model_args.vocab_size = tokenizer.n_words
|
89 |
torch.set_default_tensor_type(torch.cuda.HalfTensor)
|
90 |
model = Transformer(model_args)
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
94 |
torch.cuda.empty_cache()
|
95 |
|
96 |
-
|
97 |
-
model.load_state_dict(
|
98 |
-
del
|
99 |
torch.cuda.empty_cache()
|
100 |
|
101 |
-
# model.load_state_dict(checkpoint, strict=False)
|
102 |
-
# del checkpoint
|
103 |
vision_model = VisionModel(model_args)
|
104 |
|
105 |
torch.set_default_tensor_type(torch.FloatTensor)
|
106 |
-
|
107 |
model.load_state_dict(instruct_adapter_checkpoint, strict=False)
|
108 |
model.load_state_dict(caption_adapter_checkpoint, strict=False)
|
109 |
vision_model.load_state_dict(caption_adapter_checkpoint, strict=False)
|
@@ -152,50 +144,33 @@ def caption_generate(
|
|
152 |
return result
|
153 |
|
154 |
|
155 |
-
def download_llama_7b(ckpt_dir, tokenizer_path):
|
156 |
-
print("LLaMA-7B downloading")
|
157 |
-
os.makedirs(ckpt_dir, exist_ok=True)
|
158 |
-
ckpt_path = os.path.join(ckpt_dir, "consolidated.00.pth")
|
159 |
-
param_path = os.path.join(ckpt_dir, "params.json")
|
160 |
-
# if not os.path.exists(ckpt_path):
|
161 |
-
# os.system(
|
162 |
-
# f"wget -O {ckpt_path} https://huggingface.co/nyanko7/LLaMA-7B/resolve/main/consolidated.00.pth")
|
163 |
-
# if not os.path.exists(param_path):
|
164 |
-
# os.system(
|
165 |
-
# f"wget -O {param_path} https://huggingface.co/nyanko7/LLaMA-7B/raw/main/params.json")
|
166 |
-
# if not os.path.exists(tokenizer_path):
|
167 |
-
# os.system(
|
168 |
-
# f"wget -O {tokenizer_path} https://huggingface.co/nyanko7/LLaMA-7B/resolve/main/tokenizer.model")
|
169 |
-
# if not os.path.exists(ckpt_path):
|
170 |
-
# os.system("git lfs install")
|
171 |
-
# os.system("git clone https://huggingface.co/nyanko7/LLaMA-7B")
|
172 |
-
|
173 |
-
print("LLaMA-7B downloaded")
|
174 |
-
|
175 |
def download_llama_adapter(instruct_adapter_path, caption_adapter_path):
|
176 |
if not os.path.exists(instruct_adapter_path):
|
177 |
-
os.system(
|
|
|
178 |
|
179 |
if not os.path.exists(caption_adapter_path):
|
180 |
-
os.system(
|
|
|
181 |
|
182 |
|
183 |
# ckpt_path = "/data1/llma/7B/consolidated.00.pth"
|
184 |
# param_path = "/data1/llma/7B/params.json"
|
185 |
# tokenizer_path = "/data1/llma/tokenizer.model"
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
param_path = hf_hub_download(
|
191 |
-
|
|
|
|
|
192 |
instruct_adapter_path = "llama_adapter_len10_layer30_release.pth"
|
193 |
caption_adapter_path = "llama_adapter_len10_layer30_caption_vit_l.pth"
|
194 |
max_seq_len = 512
|
195 |
max_batch_size = 1
|
196 |
|
197 |
# download models
|
198 |
-
# download_llama_7b(ckpt_dir, tokenizer_path)
|
199 |
download_llama_adapter(instruct_adapter_path, caption_adapter_path)
|
200 |
|
201 |
local_rank, world_size = setup_model_parallel()
|
@@ -285,8 +260,9 @@ def create_caption_demo():
|
|
285 |
run_botton.click(fn=caption_generate, inputs=inputs, outputs=outputs)
|
286 |
return instruct_demo
|
287 |
|
|
|
288 |
description = """
|
289 |
-
# LLaMA-Adapter
|
290 |
The official demo for **LLaMA-Adapter: Efficient Fine-tuning of Language Models with Zero-init Attention**.
|
291 |
Please refer to our [arXiv paper](https://arxiv.org/abs/2303.16199) and [github](https://github.com/ZrrSkywalker/LLaMA-Adapter) for more details.
|
292 |
"""
|
|
|
61 |
max_batch_size: int,
|
62 |
) -> LLaMA:
|
63 |
start_time = time.time()
|
|
|
|
|
|
|
|
|
|
|
64 |
print("Loading")
|
|
|
65 |
instruct_adapter_checkpoint = torch.load(
|
66 |
instruct_adapter_path, map_location="cpu")
|
67 |
caption_adapter_checkpoint = torch.load(
|
68 |
caption_adapter_path, map_location="cpu")
|
|
|
69 |
with open(param_path, "r") as f:
|
70 |
params = json.loads(f.read())
|
71 |
|
|
|
81 |
model_args.vocab_size = tokenizer.n_words
|
82 |
torch.set_default_tensor_type(torch.cuda.HalfTensor)
|
83 |
model = Transformer(model_args)
|
84 |
+
|
85 |
+
# To reduce memory usuage
|
86 |
+
ckpt0 = torch.load(ckpt0_path, map_location='cuda')
|
87 |
+
model.load_state_dict(ckpt0, strict=False)
|
88 |
+
del ckpt0
|
89 |
torch.cuda.empty_cache()
|
90 |
|
91 |
+
ckpt1 = torch.load(ckpt1_path, map_location='cuda')
|
92 |
+
model.load_state_dict(ckpt1, strict=False)
|
93 |
+
del ckpt1
|
94 |
torch.cuda.empty_cache()
|
95 |
|
|
|
|
|
96 |
vision_model = VisionModel(model_args)
|
97 |
|
98 |
torch.set_default_tensor_type(torch.FloatTensor)
|
|
|
99 |
model.load_state_dict(instruct_adapter_checkpoint, strict=False)
|
100 |
model.load_state_dict(caption_adapter_checkpoint, strict=False)
|
101 |
vision_model.load_state_dict(caption_adapter_checkpoint, strict=False)
|
|
|
144 |
return result
|
145 |
|
146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
def download_llama_adapter(instruct_adapter_path, caption_adapter_path):
|
148 |
if not os.path.exists(instruct_adapter_path):
|
149 |
+
os.system(
|
150 |
+
f"wget -q -O {instruct_adapter_path} https://github.com/ZrrSkywalker/LLaMA-Adapter/releases/download/v.1.0.0/llama_adapter_len10_layer30_release.pth")
|
151 |
|
152 |
if not os.path.exists(caption_adapter_path):
|
153 |
+
os.system(
|
154 |
+
f"wget -q -O {caption_adapter_path} https://github.com/ZrrSkywalker/LLaMA-Adapter/releases/download/v.1.0.0/llama_adapter_len10_layer30_caption_vit_l.pth")
|
155 |
|
156 |
|
157 |
# ckpt_path = "/data1/llma/7B/consolidated.00.pth"
|
158 |
# param_path = "/data1/llma/7B/params.json"
|
159 |
# tokenizer_path = "/data1/llma/tokenizer.model"
|
160 |
+
ckpt0_path = hf_hub_download(
|
161 |
+
repo_id="csuhan/llama_storage", filename="consolidated.00_part0.pth")
|
162 |
+
ckpt1_path = hf_hub_download(
|
163 |
+
repo_id="csuhan/llama_storage", filename="consolidated.00_part1.pth")
|
164 |
+
param_path = hf_hub_download(
|
165 |
+
repo_id="nyanko7/LLaMA-7B", filename="params.json")
|
166 |
+
tokenizer_path = hf_hub_download(
|
167 |
+
repo_id="nyanko7/LLaMA-7B", filename="tokenizer.model")
|
168 |
instruct_adapter_path = "llama_adapter_len10_layer30_release.pth"
|
169 |
caption_adapter_path = "llama_adapter_len10_layer30_caption_vit_l.pth"
|
170 |
max_seq_len = 512
|
171 |
max_batch_size = 1
|
172 |
|
173 |
# download models
|
|
|
174 |
download_llama_adapter(instruct_adapter_path, caption_adapter_path)
|
175 |
|
176 |
local_rank, world_size = setup_model_parallel()
|
|
|
260 |
run_botton.click(fn=caption_generate, inputs=inputs, outputs=outputs)
|
261 |
return instruct_demo
|
262 |
|
263 |
+
|
264 |
description = """
|
265 |
+
# LLaMA-Adapter🚀
|
266 |
The official demo for **LLaMA-Adapter: Efficient Fine-tuning of Language Models with Zero-init Attention**.
|
267 |
Please refer to our [arXiv paper](https://arxiv.org/abs/2303.16199) and [github](https://github.com/ZrrSkywalker/LLaMA-Adapter) for more details.
|
268 |
"""
|
packages.txt
DELETED
File without changes
|