Skip to content

Commit 43f7a08

Browse files
committed
Fix Linux release LibTorch download
1 parent 1a7fa7f commit 43f7a08

3 files changed

Lines changed: 110 additions & 12 deletions

File tree

.github/workflows/release.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,66 @@ jobs:
5555
- name: Install Rust toolchain
5656
uses: dtolnay/rust-toolchain@stable
5757

58+
- name: Preload Linux LibTorch
59+
if: runner.os == 'Linux'
60+
working-directory: flint
61+
shell: python
62+
run: |
63+
import os
64+
import pathlib
65+
import shutil
66+
import tempfile
67+
import urllib.request
68+
import zipfile
69+
70+
version = "2.12.1"
71+
url = (
72+
"https://download.pytorch.org/libtorch/cpu/"
73+
f"libtorch-shared-with-deps-{version}%2Bcpu.zip"
74+
)
75+
target_dir = pathlib.Path(os.environ.get("CARGO_TARGET_DIR", "target"))
76+
package_dir = target_dir / "store" / "libtorch" / version / "cpu"
77+
lib_dir = package_dir / "libtorch" / "lib"
78+
required = ("libc10.so", "libtorch_cpu.so", "libtorch.so")
79+
80+
if all((lib_dir / name).is_file() for name in required):
81+
raise SystemExit(0)
82+
83+
package_dir.parent.mkdir(parents=True, exist_ok=True)
84+
staging_dir = package_dir.with_name(f"{package_dir.name}.tmp")
85+
shutil.rmtree(staging_dir, ignore_errors=True)
86+
87+
archive_path = None
88+
try:
89+
with tempfile.NamedTemporaryFile(
90+
dir=package_dir.parent, suffix=".zip", delete=False
91+
) as archive:
92+
archive_path = pathlib.Path(archive.name)
93+
request = urllib.request.Request(
94+
url, headers={"User-Agent": "flint-release-ci"}
95+
)
96+
with urllib.request.urlopen(request, timeout=300) as response:
97+
shutil.copyfileobj(response, archive, length=1024 * 1024)
98+
99+
with zipfile.ZipFile(archive_path) as zip_file:
100+
damaged = zip_file.testzip()
101+
if damaged is not None:
102+
raise RuntimeError(f"damaged LibTorch member: {damaged}")
103+
zip_file.extractall(staging_dir)
104+
105+
if not all(
106+
(staging_dir / "libtorch" / "lib" / name).is_file()
107+
for name in required
108+
):
109+
raise RuntimeError("LibTorch archive is missing required libraries")
110+
111+
shutil.rmtree(package_dir, ignore_errors=True)
112+
staging_dir.replace(package_dir)
113+
finally:
114+
if archive_path is not None:
115+
archive_path.unlink(missing_ok=True)
116+
shutil.rmtree(staging_dir, ignore_errors=True)
117+
58118
- name: Build release runner
59119
working-directory: flint
60120
run: cargo build --release --locked --bin flint-ai

Cargo.lock

Lines changed: 48 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ anyhow = "1"
1414
clap = { version = "4.5", features = ["derive"] }
1515
image = "0.25"
1616
imageproc = "0.27"
17-
koharu-runtime = { git = "https://github.com/mayocream/koharu.git", branch = "refactor/0705", package = "koharu-runtime" }
18-
koharu-torch = { git = "https://github.com/mayocream/koharu.git", branch = "refactor/0705", package = "koharu-torch" }
17+
koharu-runtime = { git = "https://github.com/mayocream/koharu.git", rev = "efdcc462427dd816d81fe4b11a5ea00ef015f805", package = "koharu-runtime" }
18+
koharu-torch = { git = "https://github.com/mayocream/koharu.git", rev = "efdcc462427dd816d81fe4b11a5ea00ef015f805", package = "koharu-torch" }
1919
pd-host-function = { path = "../rustscript/pd-host-function" }
2020
tokenizers = "0.22"
2121
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

0 commit comments

Comments
 (0)