ccloud0525 commited on
Commit ·
7909ec4
1
Parent(s): b92e396
feat: "first commit"
Browse files- modality_connector.py +12 -0
- ts_generation_mixin.py +2 -4
- util_functions.py +9 -0
modality_connector.py
CHANGED
|
@@ -8,6 +8,7 @@ from torchvision.transforms import Resize
|
|
| 8 |
from transformers import ViTImageProcessor, ViTModel, BertModel, ViTConfig, BertConfig
|
| 9 |
|
| 10 |
from .configuration_aurora import AuroraConfig
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
class VisionEncoder(nn.Module):
|
|
@@ -20,6 +21,10 @@ class VisionEncoder(nn.Module):
|
|
| 20 |
self.processor = UnifiedImageProcessor(config, self.config_path)
|
| 21 |
|
| 22 |
vit_config_file = os.path.join(self.config_path, "config.json")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
self.model = ViTModel(ViTConfig.from_json_file(vit_config_file))
|
| 24 |
|
| 25 |
for param in self.model.parameters():
|
|
@@ -79,6 +84,9 @@ class UnifiedImageProcessor(nn.Module):
|
|
| 79 |
self.config_path = vit_config_path
|
| 80 |
|
| 81 |
processor_file = os.path.join(self.config_path, "preprocessor_config.json")
|
|
|
|
|
|
|
|
|
|
| 82 |
self.vit_processor = ViTImageProcessor.from_json_file(processor_file)
|
| 83 |
|
| 84 |
self.target_size = self.vit_processor.size["height"]
|
|
@@ -136,6 +144,10 @@ class TextEncoder(nn.Module):
|
|
| 136 |
self.config_path = os.path.join(base_dir, "bert_config")
|
| 137 |
|
| 138 |
bert_config_file = os.path.join(self.config_path, "config.json")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
self.model = BertModel(BertConfig.from_json_file(bert_config_file))
|
| 140 |
|
| 141 |
for param in self.model.parameters():
|
|
|
|
| 8 |
from transformers import ViTImageProcessor, ViTModel, BertModel, ViTConfig, BertConfig
|
| 9 |
|
| 10 |
from .configuration_aurora import AuroraConfig
|
| 11 |
+
from .util_functions import resolve_subdir
|
| 12 |
|
| 13 |
|
| 14 |
class VisionEncoder(nn.Module):
|
|
|
|
| 21 |
self.processor = UnifiedImageProcessor(config, self.config_path)
|
| 22 |
|
| 23 |
vit_config_file = os.path.join(self.config_path, "config.json")
|
| 24 |
+
|
| 25 |
+
if not os.path.exists(vit_config_file):
|
| 26 |
+
resolve_subdir(repo_id="DecisionIntelligence/Aurora", subdir="vit_config", file_name="config.json")
|
| 27 |
+
|
| 28 |
self.model = ViTModel(ViTConfig.from_json_file(vit_config_file))
|
| 29 |
|
| 30 |
for param in self.model.parameters():
|
|
|
|
| 84 |
self.config_path = vit_config_path
|
| 85 |
|
| 86 |
processor_file = os.path.join(self.config_path, "preprocessor_config.json")
|
| 87 |
+
if not os.path.exists(processor_file):
|
| 88 |
+
resolve_subdir(repo_id="DecisionIntelligence/Aurora", subdir="vit_config", file_name="preprocessor_config.json")
|
| 89 |
+
|
| 90 |
self.vit_processor = ViTImageProcessor.from_json_file(processor_file)
|
| 91 |
|
| 92 |
self.target_size = self.vit_processor.size["height"]
|
|
|
|
| 144 |
self.config_path = os.path.join(base_dir, "bert_config")
|
| 145 |
|
| 146 |
bert_config_file = os.path.join(self.config_path, "config.json")
|
| 147 |
+
|
| 148 |
+
if not os.path.exists(bert_config_file):
|
| 149 |
+
resolve_subdir(repo_id="DecisionIntelligence/Aurora", subdir="bert_config", file_name="config.json")
|
| 150 |
+
|
| 151 |
self.model = BertModel(BertConfig.from_json_file(bert_config_file))
|
| 152 |
|
| 153 |
for param in self.model.parameters():
|
ts_generation_mixin.py
CHANGED
|
@@ -6,7 +6,7 @@ from transformers import BertTokenizer
|
|
| 6 |
from transformers import GenerationMixin, LogitsProcessorList, StoppingCriteriaList
|
| 7 |
from transformers.generation.utils import GenerationConfig, GenerateOutput
|
| 8 |
from transformers.utils import ModelOutput
|
| 9 |
-
|
| 10 |
|
| 11 |
class TSGenerationMixin(GenerationMixin):
|
| 12 |
_tokenizer = None
|
|
@@ -17,9 +17,7 @@ class TSGenerationMixin(GenerationMixin):
|
|
| 17 |
tokenizer_dir = os.path.join(base_dir, "bert_config")
|
| 18 |
|
| 19 |
if not os.path.isdir(tokenizer_dir):
|
| 20 |
-
|
| 21 |
-
f"BERT tokenizer directory not found: {tokenizer_dir}"
|
| 22 |
-
)
|
| 23 |
|
| 24 |
self._tokenizer = BertTokenizer.from_pretrained(
|
| 25 |
tokenizer_dir,
|
|
|
|
| 6 |
from transformers import GenerationMixin, LogitsProcessorList, StoppingCriteriaList
|
| 7 |
from transformers.generation.utils import GenerationConfig, GenerateOutput
|
| 8 |
from transformers.utils import ModelOutput
|
| 9 |
+
from .util_functions import resolve_subdir
|
| 10 |
|
| 11 |
class TSGenerationMixin(GenerationMixin):
|
| 12 |
_tokenizer = None
|
|
|
|
| 17 |
tokenizer_dir = os.path.join(base_dir, "bert_config")
|
| 18 |
|
| 19 |
if not os.path.isdir(tokenizer_dir):
|
| 20 |
+
resolve_subdir(repo_id="DecisionIntelligence/Aurora", subdir="bert_config", file_name="config.json")
|
|
|
|
|
|
|
| 21 |
|
| 22 |
self._tokenizer = BertTokenizer.from_pretrained(
|
| 23 |
tokenizer_dir,
|
util_functions.py
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
|
|
| 1 |
from typing import Tuple
|
| 2 |
|
| 3 |
import math
|
| 4 |
import torch
|
| 5 |
import torch.nn as nn
|
| 6 |
import torch.nn.functional as F
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
def resize(x_tensor, new_shape):
|
|
|
|
| 1 |
+
import os
|
| 2 |
from typing import Tuple
|
| 3 |
|
| 4 |
import math
|
| 5 |
import torch
|
| 6 |
import torch.nn as nn
|
| 7 |
import torch.nn.functional as F
|
| 8 |
+
from huggingface_hub import hf_hub_download
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def resolve_subdir(repo_id: str, subdir: str, file_name: str) -> str:
|
| 12 |
+
hf_hub_download(
|
| 13 |
+
repo_id=repo_id,
|
| 14 |
+
filename=f"{subdir}/{file_name}"
|
| 15 |
+
)
|
| 16 |
|
| 17 |
|
| 18 |
def resize(x_tensor, new_shape):
|