Browse Source

[MNT] solve the conflict

tags/v0.3.2
bxdd 2 years ago
parent
commit
9fc37bc48a
4 changed files with 10 additions and 9 deletions
  1. +3
    -0
      learnware/config.py
  2. +1
    -2
      learnware/market/heterogeneous/organizer/__init__.py
  3. +2
    -6
      learnware/market/heterogeneous/organizer/hetero_map/__init__.py
  4. +4
    -1
      learnware/market/heterogeneous/organizer/hetero_map/feature_extractor.py

+ 3
- 0
learnware/config.py View File

@@ -63,11 +63,13 @@ LEARNWARE_FOLDER_POOL_PATH = os.path.join(LEARNWARE_POOL_PATH, "learnwares")

DATABASE_PATH = os.path.join(ROOT_DIRPATH, "database")
STDOUT_PATH = os.path.join(ROOT_DIRPATH, "stdout")
CACHE_PATH = os.path.join(ROOT_DIRPATH, "cache")

# TODO: Delete them later
os.makedirs(ROOT_DIRPATH, exist_ok=True)
os.makedirs(DATABASE_PATH, exist_ok=True)
os.makedirs(STDOUT_PATH, exist_ok=True)
os.makedirs(CACHE_PATH, exist_ok=True)

semantic_config = {
"Data": {
@@ -123,6 +125,7 @@ _DEFAULT_CONFIG = {
"root_path": ROOT_DIRPATH,
"package_path": PACKAGE_DIRPATH,
"stdout_path": STDOUT_PATH,
"cache_path": CACHE_PATH,
"logging_level": logging.INFO,
"logging_outfile": None,
"semantic_specs": semantic_config,


+ 1
- 2
learnware/market/heterogeneous/organizer/__init__.py View File

@@ -21,7 +21,6 @@ class HeteroMapTableOrganizer(EasyOrganizer):
os.makedirs(hetero_folder_path, exist_ok=True)
self.market_mapping_path = os.path.join(hetero_folder_path, "model.bin")
self.hetero_specs_path = os.path.join(hetero_folder_path, "hetero_specifications")
self.training_args.update({"cache_dir": hetero_folder_path})
os.makedirs(self.hetero_specs_path, exist_ok=True)

if os.path.exists(self.market_mapping_path):
@@ -42,7 +41,7 @@ class HeteroMapTableOrganizer(EasyOrganizer):
self._update_learnware_by_ids(self.get_learnware_ids(check_status=BaseChecker.USABLE_LEARWARE))
else:
logger.warning(f"No market mapping to reload!")
self.market_mapping = HeteroMap(cache_dir=hetero_folder_path)
self.market_mapping = HeteroMap()

def reset(self, market_id, rebuild=False, auto_update=False, auto_update_limit=100, **training_args):
self.auto_update = auto_update


+ 2
- 6
learnware/market/heterogeneous/organizer/hetero_map/__init__.py View File

@@ -40,8 +40,7 @@ class HeteroMap(nn.Module):
temperature=10,
base_temperature=10,
activation="relu",
device="cpu",
cache_dir=None,
device="cuda:0",
**kwargs,
):
"""
@@ -73,8 +72,6 @@ class HeteroMap(nn.Module):
Activation function for transformer layer, by default "relu"
device : str, optional
Device to run the model on, by default "cuda:0"
cache_dir : str, optional
The cache directory, by default None
"""
super(HeteroMap, self).__init__()

@@ -88,12 +85,11 @@ class HeteroMap(nn.Module):
"ffn_dim": ffn_dim,
"projection_dim": projection_dim,
"activation": activation,
"cache_dir": cache_dir,
}
self.model_args.update(kwargs)

if feature_tokenizer is None:
feature_tokenizer = FeatureTokenizer(cache_dir=cache_dir, **kwargs)
feature_tokenizer = FeatureTokenizer(**kwargs)

self.feature_tokenizer = feature_tokenizer



+ 4
- 1
learnware/market/heterogeneous/organizer/hetero_map/feature_extractor.py View File

@@ -8,6 +8,8 @@ import torch.nn.init as nn_init
from torch import Tensor, nn
from transformers import BertTokenizerFast

from .....config import C as conf


class WordEmbedding(nn.Module):
"""Encode tokens drawn from column names"""
@@ -62,7 +64,6 @@ class FeatureTokenizer:
def __init__(
self,
disable_tokenizer_parallel=True,
cache_dir=None,
**kwargs,
):
"""
@@ -71,6 +72,8 @@ class FeatureTokenizer:
disable_tokenizer_parallel : bool, optional
true if use extractor for collator function in torch.DataLoader
"""
cache_dir = conf["cache_path"]
os.makedirs(cache_dir, exist_ok=True)
self.tokenizer = BertTokenizerFast.from_pretrained("bert-base-uncased", cache_dir=cache_dir)
self.tokenizer.__dict__["model_max_length"] = 512
if disable_tokenizer_parallel: # disable tokenizer parallel


Loading…
Cancel
Save