Upload artifact.py with huggingface_hub
Browse files- artifact.py +8 -12
artifact.py
CHANGED
|
@@ -5,7 +5,6 @@ import os
|
|
| 5 |
import pkgutil
|
| 6 |
from abc import abstractmethod
|
| 7 |
from copy import deepcopy
|
| 8 |
-
from functools import lru_cache
|
| 9 |
from typing import Dict, List, Optional, Union, final
|
| 10 |
|
| 11 |
from .dataclass import AbstractField, Dataclass, Field, InternalField, fields
|
|
@@ -16,7 +15,7 @@ from .parsing_utils import (
|
|
| 16 |
from .settings_utils import get_settings
|
| 17 |
from .text_utils import camel_to_snake_case, is_camel_case
|
| 18 |
from .type_utils import issubtype
|
| 19 |
-
from .utils import
|
| 20 |
|
| 21 |
logger = get_logger()
|
| 22 |
settings = get_settings()
|
|
@@ -151,7 +150,7 @@ class Artifact(Dataclass):
|
|
| 151 |
if cls.is_registered_type(snake_case_key):
|
| 152 |
assert (
|
| 153 |
str(cls._class_register[snake_case_key]) == str(artifact_class)
|
| 154 |
-
), f"Artifact class name must be unique, '{snake_case_key}' already exists for {cls._class_register[snake_case_key]}. Cannot be
|
| 155 |
|
| 156 |
return snake_case_key
|
| 157 |
|
|
@@ -210,7 +209,7 @@ class Artifact(Dataclass):
|
|
| 210 |
|
| 211 |
@classmethod
|
| 212 |
def load(cls, path, artifact_identifier=None, overwrite_args=None):
|
| 213 |
-
d =
|
| 214 |
new_artifact = cls.from_dict(d, overwrite_args=overwrite_args)
|
| 215 |
new_artifact.artifact_identifier = artifact_identifier
|
| 216 |
return new_artifact
|
|
@@ -298,7 +297,6 @@ class UnitxtArtifactNotFoundError(Exception):
|
|
| 298 |
return f"Artifact {self.name} does not exist, in artifactories:{self.artifactories}"
|
| 299 |
|
| 300 |
|
| 301 |
-
@lru_cache(maxsize=None)
|
| 302 |
def fetch_artifact(name):
|
| 303 |
if Artifact.is_artifact_file(name):
|
| 304 |
return Artifact.load(name), None
|
|
@@ -323,16 +321,14 @@ def get_artifactory_name_and_args(
|
|
| 323 |
raise UnitxtArtifactNotFoundError(name, artifactories)
|
| 324 |
|
| 325 |
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
logger.info(f"Artifact {identifer} is fetched from {artifactory}")
|
| 330 |
return artifact
|
| 331 |
|
| 332 |
|
| 333 |
-
def
|
| 334 |
-
|
| 335 |
-
verbosed_fetch_artifact.cache_clear()
|
| 336 |
|
| 337 |
|
| 338 |
def maybe_recover_artifact(artifact):
|
|
|
|
| 5 |
import pkgutil
|
| 6 |
from abc import abstractmethod
|
| 7 |
from copy import deepcopy
|
|
|
|
| 8 |
from typing import Dict, List, Optional, Union, final
|
| 9 |
|
| 10 |
from .dataclass import AbstractField, Dataclass, Field, InternalField, fields
|
|
|
|
| 15 |
from .settings_utils import get_settings
|
| 16 |
from .text_utils import camel_to_snake_case, is_camel_case
|
| 17 |
from .type_utils import issubtype
|
| 18 |
+
from .utils import artifacts_json_cache, save_json
|
| 19 |
|
| 20 |
logger = get_logger()
|
| 21 |
settings = get_settings()
|
|
|
|
| 150 |
if cls.is_registered_type(snake_case_key):
|
| 151 |
assert (
|
| 152 |
str(cls._class_register[snake_case_key]) == str(artifact_class)
|
| 153 |
+
), f"Artifact class name must be unique, '{snake_case_key}' already exists for {cls._class_register[snake_case_key]}. Cannot be overridden by {artifact_class}."
|
| 154 |
|
| 155 |
return snake_case_key
|
| 156 |
|
|
|
|
| 209 |
|
| 210 |
@classmethod
|
| 211 |
def load(cls, path, artifact_identifier=None, overwrite_args=None):
|
| 212 |
+
d = artifacts_json_cache(path)
|
| 213 |
new_artifact = cls.from_dict(d, overwrite_args=overwrite_args)
|
| 214 |
new_artifact.artifact_identifier = artifact_identifier
|
| 215 |
return new_artifact
|
|
|
|
| 297 |
return f"Artifact {self.name} does not exist, in artifactories:{self.artifactories}"
|
| 298 |
|
| 299 |
|
|
|
|
| 300 |
def fetch_artifact(name):
|
| 301 |
if Artifact.is_artifact_file(name):
|
| 302 |
return Artifact.load(name), None
|
|
|
|
| 321 |
raise UnitxtArtifactNotFoundError(name, artifactories)
|
| 322 |
|
| 323 |
|
| 324 |
+
def verbosed_fetch_artifact(identifier):
|
| 325 |
+
artifact, artifactory = fetch_artifact(identifier)
|
| 326 |
+
logger.info(f"Artifact {identifier} is fetched from {artifactory}")
|
|
|
|
| 327 |
return artifact
|
| 328 |
|
| 329 |
|
| 330 |
+
def reset_artifacts_json_cache():
|
| 331 |
+
artifacts_json_cache.cache_clear()
|
|
|
|
| 332 |
|
| 333 |
|
| 334 |
def maybe_recover_artifact(artifact):
|