Upload artifact.py with huggingface_hub
Browse files- artifact.py +8 -0
artifact.py
CHANGED
@@ -5,6 +5,7 @@ import os
|
|
5 |
import pkgutil
|
6 |
from abc import abstractmethod
|
7 |
from copy import deepcopy
|
|
|
8 |
from typing import Dict, List, Union, final
|
9 |
|
10 |
from .dataclass import Dataclass, Field, fields
|
@@ -252,6 +253,7 @@ class UnitxtArtifactNotFoundError(Exception):
|
|
252 |
return f"Artifact {self.name} does not exist, in artifactories:{self.artifactories}"
|
253 |
|
254 |
|
|
|
255 |
def fetch_artifact(name):
|
256 |
if Artifact.is_artifact_file(name):
|
257 |
return Artifact.load(name), None
|
@@ -263,12 +265,18 @@ def fetch_artifact(name):
|
|
263 |
raise UnitxtArtifactNotFoundError(name, Artifactories().artifactories)
|
264 |
|
265 |
|
|
|
266 |
def verbosed_fetch_artifact(identifer):
|
267 |
artifact, artifactory = fetch_artifact(identifer)
|
268 |
logger.info(f"Artifact {identifer} is fetched from {artifactory}")
|
269 |
return artifact
|
270 |
|
271 |
|
|
|
|
|
|
|
|
|
|
|
272 |
def maybe_recover_artifact(artifact):
|
273 |
if isinstance(artifact, str):
|
274 |
return verbosed_fetch_artifact(artifact)
|
|
|
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, Union, final
|
10 |
|
11 |
from .dataclass import Dataclass, Field, fields
|
|
|
253 |
return f"Artifact {self.name} does not exist, in artifactories:{self.artifactories}"
|
254 |
|
255 |
|
256 |
+
@lru_cache(maxsize=None)
|
257 |
def fetch_artifact(name):
|
258 |
if Artifact.is_artifact_file(name):
|
259 |
return Artifact.load(name), None
|
|
|
265 |
raise UnitxtArtifactNotFoundError(name, Artifactories().artifactories)
|
266 |
|
267 |
|
268 |
+
@lru_cache(maxsize=None)
|
269 |
def verbosed_fetch_artifact(identifer):
|
270 |
artifact, artifactory = fetch_artifact(identifer)
|
271 |
logger.info(f"Artifact {identifer} is fetched from {artifactory}")
|
272 |
return artifact
|
273 |
|
274 |
|
275 |
+
def reset_artifacts_cache():
|
276 |
+
fetch_artifact.cache_clear()
|
277 |
+
verbosed_fetch_artifact.cache_clear()
|
278 |
+
|
279 |
+
|
280 |
def maybe_recover_artifact(artifact):
|
281 |
if isinstance(artifact, str):
|
282 |
return verbosed_fetch_artifact(artifact)
|