-
Notifications
You must be signed in to change notification settings - Fork 630
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[iree.build] Make the fetch_http action more robust. (#19330)
* Downloads to a staging file and then atomically renames into place, avoiding potential for partial downloads. * Reports completion percent as part of the console updates. * Persists metadata for the source URL and will refetch if changed. * Fixes an error handling test for the onnx mnist_builder that missed the prior update. More sophistication is possible but this brings it up to min-viable from a usability perspective. Signed-off-by: Stella Laurenzo <[email protected]>
- Loading branch information
1 parent
d182e57
commit 9789438
Showing
5 changed files
with
201 additions
and
6 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
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 |
---|---|---|
|
@@ -20,3 +20,10 @@ iree_py_test( | |
SRCS | ||
"basic_test.py" | ||
) | ||
|
||
iree_py_test( | ||
NAME | ||
net_test | ||
SRCS | ||
"net_test.py" | ||
) |
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Copyright 2024 The IREE Authors | ||
# | ||
# Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
import io | ||
import os | ||
from pathlib import Path | ||
import tempfile | ||
import unittest | ||
|
||
from iree.build import * | ||
from iree.build.executor import BuildContext | ||
from iree.build.test_actions import ExecuteOutOfProcessThunkAction | ||
|
||
|
||
TEST_URL = None | ||
TEST_URL_1 = "https://huggingface.co/google-bert/bert-base-cased/resolve/cd5ef92a9fb2f889e972770a36d4ed042daf221e/tokenizer.json" | ||
TEST_URL_2 = "https://huggingface.co/google-bert/bert-base-cased/resolve/cd5ef92a9fb2f889e972770a36d4ed042daf221e/tokenizer_config.json" | ||
|
||
|
||
@entrypoint | ||
def tokenizer_via_http(): | ||
return fetch_http( | ||
name="tokenizer.json", | ||
url=TEST_URL, | ||
) | ||
|
||
|
||
class BasicTest(unittest.TestCase): | ||
def setUp(self): | ||
self._temp_dir = tempfile.TemporaryDirectory(ignore_cleanup_errors=True) | ||
self._temp_dir.__enter__() | ||
self.output_path = Path(self._temp_dir.name) | ||
|
||
def tearDown(self) -> None: | ||
self._temp_dir.__exit__(None, None, None) | ||
|
||
def test_fetch_http(self): | ||
# This just does a sanity check that rich console mode does not crash. Actual | ||
# behavior can really only be completely verified visually. | ||
out = None | ||
err = None | ||
global TEST_URL | ||
path = self.output_path / "genfiles" / "tokenizer_via_http" / "tokenizer.json" | ||
|
||
def run(): | ||
nonlocal out | ||
nonlocal err | ||
try: | ||
out_io = io.StringIO() | ||
err_io = io.StringIO() | ||
iree_build_main( | ||
args=[ | ||
"tokenizer_via_http", | ||
"--output-dir", | ||
str(self.output_path), | ||
"--test-force-console", | ||
], | ||
stderr=err_io, | ||
stdout=out_io, | ||
) | ||
finally: | ||
out = out_io.getvalue() | ||
err = err_io.getvalue() | ||
print(f"::test_fetch_http err: {err!r}") | ||
print(f"::test_fetch_http out: {out!r}") | ||
|
||
def assertExists(): | ||
self.assertTrue(path.exists(), msg=f"Path {path} exists") | ||
|
||
# First run should fetch. | ||
TEST_URL = TEST_URL_1 | ||
run() | ||
self.assertIn("Fetching URL: https://", err) | ||
assertExists() | ||
|
||
# Second run should not fetch. | ||
TEST_URL = TEST_URL_1 | ||
run() | ||
self.assertNotIn("Fetching URL: https://", err) | ||
assertExists() | ||
|
||
# Fetching a different URL should download again. | ||
TEST_URL = TEST_URL_2 | ||
run() | ||
self.assertIn("Fetching URL: https://", err) | ||
assertExists() | ||
|
||
# Removing the file should fetch again. | ||
TEST_URL = TEST_URL_2 | ||
path.unlink() | ||
run() | ||
self.assertIn("Fetching URL: https://", err) | ||
assertExists() | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |