-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EAGLE-5416] Added Tests for Download checkpoints and Fix download me…
…thods (#488) * also fall back to HF_TOKEN in env * older version * rc3 * fix folders with nested files * Revert "Revert "[EAGLE-5416] Added Tests for Download checkpoints and Fix dow…" This reverts commit f0d909a. * improve loader validation * also try ignoring .cache folder * use new flag in tests
- Loading branch information
Showing
11 changed files
with
225 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "11.0.3" | ||
__version__ = "11.0.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This is the sample config file for the GOT OCR2.O model. | ||
|
||
model: | ||
id: "dummy-runner-model" | ||
user_id: "user_id" | ||
app_id: "app_id" | ||
model_type_id: "multimodal-to-text" | ||
|
||
build_info: | ||
python_version: "3.11" | ||
|
||
inference_compute_info: | ||
cpu_limit: "1" | ||
cpu_memory: "1Gi" | ||
num_accelerators: 0 | ||
|
||
|
||
checkpoints: | ||
type: "huggingface" | ||
repo_id: "timm/mobilenetv3_small_100.lamb_in1k" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import os | ||
import shutil | ||
import tempfile | ||
|
||
import pytest | ||
|
||
from clarifai.runners.models.model_upload import ModelUploader | ||
from clarifai.runners.utils.loader import HuggingFaceLoader | ||
|
||
MODEL_ID = "timm/mobilenetv3_small_100.lamb_in1k" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def checkpoint_dir(): | ||
# Create a temporary directory for the test checkpoints | ||
temp_dir = os.path.join(tempfile.gettempdir(), MODEL_ID[5:]) | ||
if not os.path.exists(temp_dir): | ||
os.makedirs(temp_dir) | ||
yield temp_dir # Provide the directory to the tests | ||
# Cleanup: remove the directory after all tests are complete | ||
shutil.rmtree(temp_dir, ignore_errors=True) | ||
|
||
|
||
# Pytest fixture to delete the checkpoints in dummy runner models folder after tests complete | ||
@pytest.fixture(scope="function") | ||
def dummy_runner_models_dir(): | ||
model_folder_path = os.path.join(os.path.dirname(__file__), "dummy_runner_models") | ||
checkpoints_path = os.path.join(model_folder_path, "1", "checkpoints") | ||
yield checkpoints_path | ||
# Cleanup the checkpoints folder after the test | ||
if os.path.exists(checkpoints_path): | ||
shutil.rmtree(checkpoints_path) | ||
|
||
|
||
@pytest.fixture(scope="function", autouse=True) | ||
def override_environment_variables(): | ||
# Backup the existing environment variable value | ||
original_clarifai_pat = os.environ.get("CLARIFAI_PAT") | ||
if "CLARIFAI_PAT" in os.environ: | ||
del os.environ["CLARIFAI_PAT"] # Temporarily unset the variable for the tests | ||
yield | ||
# Restore the original environment variable value after tests | ||
if original_clarifai_pat: | ||
os.environ["CLARIFAI_PAT"] = original_clarifai_pat | ||
|
||
|
||
def test_loader_download_checkpoints(checkpoint_dir): | ||
loader = HuggingFaceLoader(repo_id=MODEL_ID) | ||
loader.download_checkpoints(checkpoint_path=checkpoint_dir) | ||
assert len(os.listdir(checkpoint_dir)) == 4 | ||
|
||
|
||
def test_validate_download(checkpoint_dir): | ||
loader = HuggingFaceLoader(repo_id=MODEL_ID) | ||
assert loader.validate_download(checkpoint_path=checkpoint_dir) is True | ||
|
||
|
||
def test_download_checkpoints(dummy_runner_models_dir): | ||
model_folder_path = os.path.join(os.path.dirname(__file__), "dummy_runner_models") | ||
model_upload = ModelUploader(model_folder_path, download_validation_only=True) | ||
isdownloaded = model_upload.download_checkpoints() | ||
assert isdownloaded is True |
Oops, something went wrong.