Add print statements
Browse files- modeling_cogvlm.py +93 -93
modeling_cogvlm.py
CHANGED
@@ -243,33 +243,33 @@ class VisionExpertAttention(nn.Module):
|
|
243 |
|
244 |
if print_values:
|
245 |
|
246 |
-
torch.save(query_states, "query_states.pt")
|
247 |
-
torch.save(key_states, "key_states.pt")
|
248 |
-
torch.save(value_states, "value_states.pt")
|
249 |
-
|
250 |
-
from huggingface_hub import HfApi
|
251 |
-
|
252 |
-
api = HfApi()
|
253 |
-
api.upload_file(
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
)
|
259 |
-
api = HfApi()
|
260 |
-
api.upload_file(
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
)
|
266 |
-
api = HfApi()
|
267 |
-
api.upload_file(
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
)
|
273 |
|
274 |
kv_seq_len = key_states.shape[-2]
|
275 |
if past_key_value is not None:
|
@@ -473,31 +473,31 @@ class CogVLMModel(CogVLMPreTrainedModel):
|
|
473 |
images_features = rearrange(images_features, 'b n d -> (b n) d')
|
474 |
images_features = images_features.to(dtype=inputs_embeds.dtype, device=inputs_embeds.device)
|
475 |
|
476 |
-
from huggingface_hub import HfApi
|
477 |
|
478 |
-
torch.save(images_features, "images_features.pt")
|
479 |
-
torch.save(inputs_embeds, "inputs_embeds.pt")
|
480 |
-
torch.save(token_type_ids, "token_type_ids.pt")
|
481 |
|
482 |
-
api = HfApi()
|
483 |
-
api.upload_file(
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
)
|
489 |
-
api.upload_file(
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
)
|
495 |
-
api.upload_file(
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
)
|
501 |
|
502 |
# print("First values of text embeddings:", inputs_embeds[0, :3, :3])
|
503 |
# print("First values of images_features:", images_features[0, :3])
|
@@ -590,41 +590,41 @@ class CogVLMModel(CogVLMPreTrainedModel):
|
|
590 |
|
591 |
hidden_states = inputs_embeds
|
592 |
|
593 |
-
torch.save(hidden_states, "initial_hidden_states.pt")
|
594 |
-
torch.save(attention_mask, "initial_attention_mask.pt")
|
595 |
-
torch.save(token_type_ids, "initial_token_type_ids.pt")
|
596 |
-
torch.save(position_ids, "initial_position_ids.pt")
|
597 |
|
598 |
-
from huggingface_hub import HfApi
|
599 |
-
|
600 |
-
api = HfApi()
|
601 |
-
api.upload_file(
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
)
|
607 |
-
api = HfApi()
|
608 |
-
api.upload_file(
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
)
|
614 |
-
api = HfApi()
|
615 |
-
api.upload_file(
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
)
|
621 |
-
api = HfApi()
|
622 |
-
api.upload_file(
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
)
|
628 |
|
629 |
# decoder layers
|
630 |
all_hidden_states = () if output_hidden_states else None
|
@@ -648,16 +648,16 @@ class CogVLMModel(CogVLMPreTrainedModel):
|
|
648 |
)
|
649 |
hidden_states = layer_outputs[0]
|
650 |
|
651 |
-
if idx == 0:
|
652 |
-
|
653 |
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
|
662 |
if use_cache:
|
663 |
next_decoder_cache += (layer_outputs[2 if output_attentions else 1],)
|
|
|
243 |
|
244 |
if print_values:
|
245 |
|
246 |
+
# torch.save(query_states, "query_states.pt")
|
247 |
+
# torch.save(key_states, "key_states.pt")
|
248 |
+
# torch.save(value_states, "value_states.pt")
|
249 |
+
|
250 |
+
# from huggingface_hub import HfApi
|
251 |
+
|
252 |
+
# api = HfApi()
|
253 |
+
# api.upload_file(
|
254 |
+
# path_or_fileobj="query_states.pt",
|
255 |
+
# path_in_repo="query_states.pt",
|
256 |
+
# repo_id="nielsr/test-cogvlm",
|
257 |
+
# repo_type="dataset",
|
258 |
+
# )
|
259 |
+
# api = HfApi()
|
260 |
+
# api.upload_file(
|
261 |
+
# path_or_fileobj="key_states.pt",
|
262 |
+
# path_in_repo="key_states.pt",
|
263 |
+
# repo_id="nielsr/test-cogvlm",
|
264 |
+
# repo_type="dataset",
|
265 |
+
# )
|
266 |
+
# api = HfApi()
|
267 |
+
# api.upload_file(
|
268 |
+
# path_or_fileobj="value_states.pt",
|
269 |
+
# path_in_repo="value_states.pt",
|
270 |
+
# repo_id="nielsr/test-cogvlm",
|
271 |
+
# repo_type="dataset",
|
272 |
+
# )
|
273 |
|
274 |
kv_seq_len = key_states.shape[-2]
|
275 |
if past_key_value is not None:
|
|
|
473 |
images_features = rearrange(images_features, 'b n d -> (b n) d')
|
474 |
images_features = images_features.to(dtype=inputs_embeds.dtype, device=inputs_embeds.device)
|
475 |
|
476 |
+
# from huggingface_hub import HfApi
|
477 |
|
478 |
+
# torch.save(images_features, "images_features.pt")
|
479 |
+
# torch.save(inputs_embeds, "inputs_embeds.pt")
|
480 |
+
# torch.save(token_type_ids, "token_type_ids.pt")
|
481 |
|
482 |
+
# api = HfApi()
|
483 |
+
# api.upload_file(
|
484 |
+
# path_or_fileobj="images_features.pt",
|
485 |
+
# path_in_repo="images_features.pt",
|
486 |
+
# repo_id="nielsr/test-cogvlm",
|
487 |
+
# repo_type="dataset",
|
488 |
+
# )
|
489 |
+
# api.upload_file(
|
490 |
+
# path_or_fileobj="inputs_embeds.pt",
|
491 |
+
# path_in_repo="inputs_embeds.pt",
|
492 |
+
# repo_id="nielsr/test-cogvlm",
|
493 |
+
# repo_type="dataset",
|
494 |
+
# )
|
495 |
+
# api.upload_file(
|
496 |
+
# path_or_fileobj="token_type_ids.pt",
|
497 |
+
# path_in_repo="token_type_ids.pt",
|
498 |
+
# repo_id="nielsr/test-cogvlm",
|
499 |
+
# repo_type="dataset",
|
500 |
+
# )
|
501 |
|
502 |
# print("First values of text embeddings:", inputs_embeds[0, :3, :3])
|
503 |
# print("First values of images_features:", images_features[0, :3])
|
|
|
590 |
|
591 |
hidden_states = inputs_embeds
|
592 |
|
593 |
+
# torch.save(hidden_states, "initial_hidden_states.pt")
|
594 |
+
# torch.save(attention_mask, "initial_attention_mask.pt")
|
595 |
+
# torch.save(token_type_ids, "initial_token_type_ids.pt")
|
596 |
+
# torch.save(position_ids, "initial_position_ids.pt")
|
597 |
|
598 |
+
# from huggingface_hub import HfApi
|
599 |
+
|
600 |
+
# api = HfApi()
|
601 |
+
# api.upload_file(
|
602 |
+
# path_or_fileobj="initial_hidden_states.pt",
|
603 |
+
# path_in_repo="initial_hidden_states.pt",
|
604 |
+
# repo_id="nielsr/test-cogvlm",
|
605 |
+
# repo_type="dataset",
|
606 |
+
# )
|
607 |
+
# api = HfApi()
|
608 |
+
# api.upload_file(
|
609 |
+
# path_or_fileobj="initial_attention_mask.pt",
|
610 |
+
# path_in_repo="initial_attention_mask.pt",
|
611 |
+
# repo_id="nielsr/test-cogvlm",
|
612 |
+
# repo_type="dataset",
|
613 |
+
# )
|
614 |
+
# api = HfApi()
|
615 |
+
# api.upload_file(
|
616 |
+
# path_or_fileobj="initial_token_type_ids.pt",
|
617 |
+
# path_in_repo="initial_token_type_ids.pt",
|
618 |
+
# repo_id="nielsr/test-cogvlm",
|
619 |
+
# repo_type="dataset",
|
620 |
+
# )
|
621 |
+
# api = HfApi()
|
622 |
+
# api.upload_file(
|
623 |
+
# path_or_fileobj="initial_position_ids.pt",
|
624 |
+
# path_in_repo="initial_position_ids.pt",
|
625 |
+
# repo_id="nielsr/test-cogvlm",
|
626 |
+
# repo_type="dataset",
|
627 |
+
# )
|
628 |
|
629 |
# decoder layers
|
630 |
all_hidden_states = () if output_hidden_states else None
|
|
|
648 |
)
|
649 |
hidden_states = layer_outputs[0]
|
650 |
|
651 |
+
# if idx == 0:
|
652 |
+
# torch.save(hidden_states, "hidden_states_after_layer_0.pt")
|
653 |
|
654 |
+
# api = HfApi()
|
655 |
+
# api.upload_file(
|
656 |
+
# path_or_fileobj="hidden_states_after_layer_0.pt",
|
657 |
+
# path_in_repo="hidden_states_after_layer_0.pt",
|
658 |
+
# repo_id="nielsr/test-cogvlm",
|
659 |
+
# repo_type="dataset",
|
660 |
+
# )
|
661 |
|
662 |
if use_cache:
|
663 |
next_decoder_cache += (layer_outputs[2 if output_attentions else 1],)
|