Hongyu Zhou
commited on
Commit
•
cfb037b
1
Parent(s):
908ff76
update cpu config
Browse files- __pycache__/utils.cpython-39.pyc +0 -0
- inference.py +1 -0
- medomni/__pycache__/__init__.cpython-39.pyc +0 -0
- medomni/common/__pycache__/__init__.cpython-39.pyc +0 -0
- medomni/common/__pycache__/config.cpython-39.pyc +0 -0
- medomni/common/__pycache__/dist_utils.cpython-39.pyc +0 -0
- medomni/common/__pycache__/logger.cpython-39.pyc +0 -0
- medomni/common/__pycache__/registry.cpython-39.pyc +0 -0
- medomni/common/__pycache__/utils.cpython-39.pyc +0 -0
- medomni/datasets/__pycache__/__init__.cpython-39.pyc +0 -0
- medomni/datasets/__pycache__/data_utils.cpython-39.pyc +0 -0
- medomni/datasets/builders/__pycache__/__init__.cpython-39.pyc +0 -0
- medomni/datasets/builders/__pycache__/base_dataset_builder.cpython-39.pyc +0 -0
- medomni/datasets/builders/__pycache__/image_text_pair_builder.cpython-39.pyc +0 -0
- medomni/datasets/datasets/__pycache__/__init__.cpython-39.pyc +0 -0
- medomni/datasets/datasets/__pycache__/base_dataset.cpython-39.pyc +0 -0
- medomni/datasets/datasets/__pycache__/caption_datasets.cpython-39.pyc +0 -0
- medomni/datasets/datasets/__pycache__/cc_sbu_dataset.cpython-39.pyc +0 -0
- medomni/datasets/datasets/__pycache__/laion_dataset.cpython-39.pyc +0 -0
- medomni/datasets/datasets/__pycache__/med_dataset.cpython-39.pyc +0 -0
- medomni/datasets/datasets/__pycache__/medcaption_datasets.cpython-39.pyc +0 -0
- medomni/models/__pycache__/Qformer.cpython-39.pyc +0 -0
- medomni/models/__pycache__/UNet.cpython-39.pyc +0 -0
- medomni/models/__pycache__/__init__.cpython-39.pyc +0 -0
- medomni/models/__pycache__/base_model.cpython-39.pyc +0 -0
- medomni/models/__pycache__/blip2.cpython-39.pyc +0 -0
- medomni/models/__pycache__/eva_vit.cpython-39.pyc +0 -0
- medomni/models/__pycache__/medomni.cpython-39.pyc +0 -0
- medomni/models/__pycache__/modeling_llama.cpython-39.pyc +0 -0
- medomni/models/blip2.py +2 -2
- medomni/models/medomni.py +7 -7
- medomni/processors/__pycache__/__init__.cpython-39.pyc +0 -0
- medomni/processors/__pycache__/base_processor.cpython-39.pyc +0 -0
- medomni/processors/__pycache__/blip_processors.cpython-39.pyc +0 -0
- medomni/processors/__pycache__/randaugment.cpython-39.pyc +0 -0
- medomni/tasks/__pycache__/__init__.cpython-39.pyc +0 -0
- medomni/tasks/__pycache__/base_task.cpython-39.pyc +0 -0
- medomni/tasks/__pycache__/image_text_pretrain.cpython-39.pyc +0 -0
__pycache__/utils.cpython-39.pyc
CHANGED
Binary files a/__pycache__/utils.cpython-39.pyc and b/__pycache__/utils.cpython-39.pyc differ
|
|
inference.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
from utils import *
|
2 |
from torch import cuda
|
|
|
3 |
|
4 |
# --- Launch Model ---
|
5 |
device = 'cuda' if cuda.is_available() else 'cpu'
|
|
|
1 |
from utils import *
|
2 |
from torch import cuda
|
3 |
+
import ipdb
|
4 |
|
5 |
# --- Launch Model ---
|
6 |
device = 'cuda' if cuda.is_available() else 'cpu'
|
medomni/__pycache__/__init__.cpython-39.pyc
CHANGED
Binary files a/medomni/__pycache__/__init__.cpython-39.pyc and b/medomni/__pycache__/__init__.cpython-39.pyc differ
|
|
medomni/common/__pycache__/__init__.cpython-39.pyc
CHANGED
Binary files a/medomni/common/__pycache__/__init__.cpython-39.pyc and b/medomni/common/__pycache__/__init__.cpython-39.pyc differ
|
|
medomni/common/__pycache__/config.cpython-39.pyc
CHANGED
Binary files a/medomni/common/__pycache__/config.cpython-39.pyc and b/medomni/common/__pycache__/config.cpython-39.pyc differ
|
|
medomni/common/__pycache__/dist_utils.cpython-39.pyc
CHANGED
Binary files a/medomni/common/__pycache__/dist_utils.cpython-39.pyc and b/medomni/common/__pycache__/dist_utils.cpython-39.pyc differ
|
|
medomni/common/__pycache__/logger.cpython-39.pyc
CHANGED
Binary files a/medomni/common/__pycache__/logger.cpython-39.pyc and b/medomni/common/__pycache__/logger.cpython-39.pyc differ
|
|
medomni/common/__pycache__/registry.cpython-39.pyc
CHANGED
Binary files a/medomni/common/__pycache__/registry.cpython-39.pyc and b/medomni/common/__pycache__/registry.cpython-39.pyc differ
|
|
medomni/common/__pycache__/utils.cpython-39.pyc
CHANGED
Binary files a/medomni/common/__pycache__/utils.cpython-39.pyc and b/medomni/common/__pycache__/utils.cpython-39.pyc differ
|
|
medomni/datasets/__pycache__/__init__.cpython-39.pyc
CHANGED
Binary files a/medomni/datasets/__pycache__/__init__.cpython-39.pyc and b/medomni/datasets/__pycache__/__init__.cpython-39.pyc differ
|
|
medomni/datasets/__pycache__/data_utils.cpython-39.pyc
CHANGED
Binary files a/medomni/datasets/__pycache__/data_utils.cpython-39.pyc and b/medomni/datasets/__pycache__/data_utils.cpython-39.pyc differ
|
|
medomni/datasets/builders/__pycache__/__init__.cpython-39.pyc
CHANGED
Binary files a/medomni/datasets/builders/__pycache__/__init__.cpython-39.pyc and b/medomni/datasets/builders/__pycache__/__init__.cpython-39.pyc differ
|
|
medomni/datasets/builders/__pycache__/base_dataset_builder.cpython-39.pyc
CHANGED
Binary files a/medomni/datasets/builders/__pycache__/base_dataset_builder.cpython-39.pyc and b/medomni/datasets/builders/__pycache__/base_dataset_builder.cpython-39.pyc differ
|
|
medomni/datasets/builders/__pycache__/image_text_pair_builder.cpython-39.pyc
CHANGED
Binary files a/medomni/datasets/builders/__pycache__/image_text_pair_builder.cpython-39.pyc and b/medomni/datasets/builders/__pycache__/image_text_pair_builder.cpython-39.pyc differ
|
|
medomni/datasets/datasets/__pycache__/__init__.cpython-39.pyc
CHANGED
Binary files a/medomni/datasets/datasets/__pycache__/__init__.cpython-39.pyc and b/medomni/datasets/datasets/__pycache__/__init__.cpython-39.pyc differ
|
|
medomni/datasets/datasets/__pycache__/base_dataset.cpython-39.pyc
CHANGED
Binary files a/medomni/datasets/datasets/__pycache__/base_dataset.cpython-39.pyc and b/medomni/datasets/datasets/__pycache__/base_dataset.cpython-39.pyc differ
|
|
medomni/datasets/datasets/__pycache__/caption_datasets.cpython-39.pyc
CHANGED
Binary files a/medomni/datasets/datasets/__pycache__/caption_datasets.cpython-39.pyc and b/medomni/datasets/datasets/__pycache__/caption_datasets.cpython-39.pyc differ
|
|
medomni/datasets/datasets/__pycache__/cc_sbu_dataset.cpython-39.pyc
CHANGED
Binary files a/medomni/datasets/datasets/__pycache__/cc_sbu_dataset.cpython-39.pyc and b/medomni/datasets/datasets/__pycache__/cc_sbu_dataset.cpython-39.pyc differ
|
|
medomni/datasets/datasets/__pycache__/laion_dataset.cpython-39.pyc
CHANGED
Binary files a/medomni/datasets/datasets/__pycache__/laion_dataset.cpython-39.pyc and b/medomni/datasets/datasets/__pycache__/laion_dataset.cpython-39.pyc differ
|
|
medomni/datasets/datasets/__pycache__/med_dataset.cpython-39.pyc
CHANGED
Binary files a/medomni/datasets/datasets/__pycache__/med_dataset.cpython-39.pyc and b/medomni/datasets/datasets/__pycache__/med_dataset.cpython-39.pyc differ
|
|
medomni/datasets/datasets/__pycache__/medcaption_datasets.cpython-39.pyc
CHANGED
Binary files a/medomni/datasets/datasets/__pycache__/medcaption_datasets.cpython-39.pyc and b/medomni/datasets/datasets/__pycache__/medcaption_datasets.cpython-39.pyc differ
|
|
medomni/models/__pycache__/Qformer.cpython-39.pyc
CHANGED
Binary files a/medomni/models/__pycache__/Qformer.cpython-39.pyc and b/medomni/models/__pycache__/Qformer.cpython-39.pyc differ
|
|
medomni/models/__pycache__/UNet.cpython-39.pyc
CHANGED
Binary files a/medomni/models/__pycache__/UNet.cpython-39.pyc and b/medomni/models/__pycache__/UNet.cpython-39.pyc differ
|
|
medomni/models/__pycache__/__init__.cpython-39.pyc
CHANGED
Binary files a/medomni/models/__pycache__/__init__.cpython-39.pyc and b/medomni/models/__pycache__/__init__.cpython-39.pyc differ
|
|
medomni/models/__pycache__/base_model.cpython-39.pyc
CHANGED
Binary files a/medomni/models/__pycache__/base_model.cpython-39.pyc and b/medomni/models/__pycache__/base_model.cpython-39.pyc differ
|
|
medomni/models/__pycache__/blip2.cpython-39.pyc
CHANGED
Binary files a/medomni/models/__pycache__/blip2.cpython-39.pyc and b/medomni/models/__pycache__/blip2.cpython-39.pyc differ
|
|
medomni/models/__pycache__/eva_vit.cpython-39.pyc
CHANGED
Binary files a/medomni/models/__pycache__/eva_vit.cpython-39.pyc and b/medomni/models/__pycache__/eva_vit.cpython-39.pyc differ
|
|
medomni/models/__pycache__/medomni.cpython-39.pyc
CHANGED
Binary files a/medomni/models/__pycache__/medomni.cpython-39.pyc and b/medomni/models/__pycache__/medomni.cpython-39.pyc differ
|
|
medomni/models/__pycache__/modeling_llama.cpython-39.pyc
CHANGED
Binary files a/medomni/models/__pycache__/modeling_llama.cpython-39.pyc and b/medomni/models/__pycache__/modeling_llama.cpython-39.pyc differ
|
|
medomni/models/blip2.py
CHANGED
@@ -32,10 +32,10 @@ class Blip2Base(BaseModel):
|
|
32 |
tokenizer.add_special_tokens({"bos_token": "[DEC]"})
|
33 |
return tokenizer
|
34 |
|
35 |
-
def maybe_autocast(self, dtype=torch.float16):
|
36 |
# if on cpu, don't use autocast
|
37 |
# if on gpu, use autocast with dtype if provided, otherwise use torch.float16
|
38 |
-
enable_autocast =
|
39 |
|
40 |
if enable_autocast:
|
41 |
return torch.cuda.amp.autocast(dtype=dtype)
|
|
|
32 |
tokenizer.add_special_tokens({"bos_token": "[DEC]"})
|
33 |
return tokenizer
|
34 |
|
35 |
+
def maybe_autocast(self, device, dtype=torch.float16):
|
36 |
# if on cpu, don't use autocast
|
37 |
# if on gpu, use autocast with dtype if provided, otherwise use torch.float16
|
38 |
+
enable_autocast = device != torch.device("cpu")
|
39 |
|
40 |
if enable_autocast:
|
41 |
return torch.cuda.amp.autocast(dtype=dtype)
|
medomni/models/medomni.py
CHANGED
@@ -285,8 +285,8 @@ class MedOmni(Blip2Base, PyTorchModelHubMixin):
|
|
285 |
if self.low_resource:
|
286 |
self.vit_to_cpu()
|
287 |
image = image.to("cpu")
|
288 |
-
|
289 |
-
with self.maybe_autocast():
|
290 |
if 'ct' in modals:
|
291 |
image_embeds_list = self.visual_encoder_3d(image, encoder_only=True)
|
292 |
image_embeds_list = [_.to(device) for _ in image_embeds_list]
|
@@ -414,7 +414,7 @@ class MedOmni(Blip2Base, PyTorchModelHubMixin):
|
|
414 |
to_regress_embeds = self.embed_tokens(to_regress_tokens.input_ids)
|
415 |
inputs_embeds = torch.cat([bos_embeds, img_embeds, to_regress_embeds], dim=1)
|
416 |
attention_mask = torch.cat([atts_bos, atts_img, to_regress_tokens.attention_mask], dim=1)
|
417 |
-
with self.maybe_autocast():
|
418 |
outputs = self.llama_model(
|
419 |
inputs_embeds=inputs_embeds,
|
420 |
attention_mask=attention_mask,
|
@@ -425,7 +425,7 @@ class MedOmni(Blip2Base, PyTorchModelHubMixin):
|
|
425 |
loss = outputs.loss
|
426 |
|
427 |
if 'detection' in samples['task_type']:
|
428 |
-
with self.maybe_autocast():
|
429 |
hidden_states = outputs.hidden_states[-1]
|
430 |
token_mask = targets == self.det_token_idx
|
431 |
target_states = hidden_states[token_mask]
|
@@ -437,7 +437,7 @@ class MedOmni(Blip2Base, PyTorchModelHubMixin):
|
|
437 |
loss += det_loss * 1e2
|
438 |
|
439 |
if 'keypoint' in samples['task_type']:
|
440 |
-
with self.maybe_autocast():
|
441 |
hidden_states = outputs.hidden_states[-1]
|
442 |
token_mask = targets == self.point_token_idx_2d
|
443 |
target_states = hidden_states[token_mask]
|
@@ -451,7 +451,7 @@ class MedOmni(Blip2Base, PyTorchModelHubMixin):
|
|
451 |
if 'segmentation' in samples['task_type']:
|
452 |
if 'ct' in samples['modal']:
|
453 |
masks = samples['answer_img']
|
454 |
-
with self.maybe_autocast():
|
455 |
img_embeds_list = self.visual_encoder_3d(image, encoder_only=True)
|
456 |
img_embeds_list = [_.to(targets.device) for _ in img_embeds_list]
|
457 |
hidden_states = outputs.hidden_states[-1]
|
@@ -466,7 +466,7 @@ class MedOmni(Blip2Base, PyTorchModelHubMixin):
|
|
466 |
loss += self.seg_loss(seg_preds, masks.float()) # +
|
467 |
else:
|
468 |
masks = samples['answer_img']
|
469 |
-
with self.maybe_autocast():
|
470 |
feats = self.model_seg_2d.encoder(image[:,0])
|
471 |
last_feats = feats[-1]
|
472 |
hidden_states = outputs.hidden_states[-1]
|
|
|
285 |
if self.low_resource:
|
286 |
self.vit_to_cpu()
|
287 |
image = image.to("cpu")
|
288 |
+
ipdb.set_trace()
|
289 |
+
with self.maybe_autocast(device):
|
290 |
if 'ct' in modals:
|
291 |
image_embeds_list = self.visual_encoder_3d(image, encoder_only=True)
|
292 |
image_embeds_list = [_.to(device) for _ in image_embeds_list]
|
|
|
414 |
to_regress_embeds = self.embed_tokens(to_regress_tokens.input_ids)
|
415 |
inputs_embeds = torch.cat([bos_embeds, img_embeds, to_regress_embeds], dim=1)
|
416 |
attention_mask = torch.cat([atts_bos, atts_img, to_regress_tokens.attention_mask], dim=1)
|
417 |
+
with self.maybe_autocast(image.device):
|
418 |
outputs = self.llama_model(
|
419 |
inputs_embeds=inputs_embeds,
|
420 |
attention_mask=attention_mask,
|
|
|
425 |
loss = outputs.loss
|
426 |
|
427 |
if 'detection' in samples['task_type']:
|
428 |
+
with self.maybe_autocast(image.device):
|
429 |
hidden_states = outputs.hidden_states[-1]
|
430 |
token_mask = targets == self.det_token_idx
|
431 |
target_states = hidden_states[token_mask]
|
|
|
437 |
loss += det_loss * 1e2
|
438 |
|
439 |
if 'keypoint' in samples['task_type']:
|
440 |
+
with self.maybe_autocast(image.device):
|
441 |
hidden_states = outputs.hidden_states[-1]
|
442 |
token_mask = targets == self.point_token_idx_2d
|
443 |
target_states = hidden_states[token_mask]
|
|
|
451 |
if 'segmentation' in samples['task_type']:
|
452 |
if 'ct' in samples['modal']:
|
453 |
masks = samples['answer_img']
|
454 |
+
with self.maybe_autocast(image.device):
|
455 |
img_embeds_list = self.visual_encoder_3d(image, encoder_only=True)
|
456 |
img_embeds_list = [_.to(targets.device) for _ in img_embeds_list]
|
457 |
hidden_states = outputs.hidden_states[-1]
|
|
|
466 |
loss += self.seg_loss(seg_preds, masks.float()) # +
|
467 |
else:
|
468 |
masks = samples['answer_img']
|
469 |
+
with self.maybe_autocast(image.device):
|
470 |
feats = self.model_seg_2d.encoder(image[:,0])
|
471 |
last_feats = feats[-1]
|
472 |
hidden_states = outputs.hidden_states[-1]
|
medomni/processors/__pycache__/__init__.cpython-39.pyc
CHANGED
Binary files a/medomni/processors/__pycache__/__init__.cpython-39.pyc and b/medomni/processors/__pycache__/__init__.cpython-39.pyc differ
|
|
medomni/processors/__pycache__/base_processor.cpython-39.pyc
CHANGED
Binary files a/medomni/processors/__pycache__/base_processor.cpython-39.pyc and b/medomni/processors/__pycache__/base_processor.cpython-39.pyc differ
|
|
medomni/processors/__pycache__/blip_processors.cpython-39.pyc
CHANGED
Binary files a/medomni/processors/__pycache__/blip_processors.cpython-39.pyc and b/medomni/processors/__pycache__/blip_processors.cpython-39.pyc differ
|
|
medomni/processors/__pycache__/randaugment.cpython-39.pyc
CHANGED
Binary files a/medomni/processors/__pycache__/randaugment.cpython-39.pyc and b/medomni/processors/__pycache__/randaugment.cpython-39.pyc differ
|
|
medomni/tasks/__pycache__/__init__.cpython-39.pyc
CHANGED
Binary files a/medomni/tasks/__pycache__/__init__.cpython-39.pyc and b/medomni/tasks/__pycache__/__init__.cpython-39.pyc differ
|
|
medomni/tasks/__pycache__/base_task.cpython-39.pyc
CHANGED
Binary files a/medomni/tasks/__pycache__/base_task.cpython-39.pyc and b/medomni/tasks/__pycache__/base_task.cpython-39.pyc differ
|
|
medomni/tasks/__pycache__/image_text_pretrain.cpython-39.pyc
CHANGED
Binary files a/medomni/tasks/__pycache__/image_text_pretrain.cpython-39.pyc and b/medomni/tasks/__pycache__/image_text_pretrain.cpython-39.pyc differ
|
|