Commit ce04cfe3 authored by zhanggzh's avatar zhanggzh
Browse files

add torchaudio2.4.1 source code

parent e8cbe177
#!/bin/bash
rm -rf build
rm -rf *.egg-info
pip3 install -r requirements.txt
export USE_RCOM=1
shopt -u nocasematch
python setup.py bdist_wheel
__version__ = '2.4.1'
__hcu_version__ = '2.4.1+das.dtk2504'
...@@ -30,12 +30,10 @@ def _get_version(sha): ...@@ -30,12 +30,10 @@ def _get_version(sha):
return version return version
def _make_version_file(version, sha): def _make_version_file(version):
sha = "Unknown" if sha is None else sha
version_path = ROOT_DIR / "src" / "torchaudio" / "version.py" version_path = ROOT_DIR / "src" / "torchaudio" / "version.py"
with open(version_path, "w") as f: with open(version_path, "w") as f:
f.write(f"__version__ = '{version}'\n") f.write(f"__version__ = '{version}'\n")
f.write(f"git_version = '{sha}'\n")
def _get_pytorch_version(): def _get_pytorch_version():
...@@ -63,6 +61,22 @@ class clean(distutils.command.clean.clean): ...@@ -63,6 +61,22 @@ class clean(distutils.command.clean.clean):
shutil.rmtree(str(path), ignore_errors=True) shutil.rmtree(str(path), ignore_errors=True)
def _make_version_file(version):
ROCM_PATH = os.getenv('ROCM_PATH')
dtk_path = ROCM_PATH + '/.info/rocm_version'
with open(dtk_path, 'r') as file:
content = file.read().strip()
dtk_version = content.replace('.', '')
hcu_version = f"{version}+das.dtk{dtk_version}"
version_path = ROOT_DIR / "packaging" / "torchaudio" /"version.py"
with open(version_path, "w") as f:
f.write(f"__version__ = '{version}'\n")
f.write(f"__hcu_version__ = '{hcu_version}'\n")
return hcu_version
def _parse_url(path): def _parse_url(path):
with open(path, "r") as file_: with open(path, "r") as file_:
for line in file_: for line in file_:
...@@ -79,6 +93,32 @@ def _fetch_archives(src): ...@@ -79,6 +93,32 @@ def _fetch_archives(src):
torch.hub.download_url_to_file(url, dest, progress=False) torch.hub.download_url_to_file(url, dest, progress=False)
import re
def get_version(file_path: str = "version.txt", encoding: str = "utf-8") -> str | None:
"""
从指定文件中读取版本号(默认文件为 version.txt)
"""
try:
with open(file_path, "r", encoding=encoding) as file:
line = file.readline().strip()
# 正则匹配语义化版本号格式(如 v1.2.3 或 4.5.6-beta)
if re.match(r"^v?(?:\d+\.){2}\d+(-\w+)?$", line):
return line
else:
print(f"[错误] 无效的版本号格式: {line}")
return None
except FileNotFoundError:
print(f"[错误] 文件不存在: {file_path}")
except UnicodeDecodeError:
print(f"[错误] 编码不匹配,请尝试 encoding='gbk'")
except Exception as e:
print(f"[错误] 读取失败: {str(e)}")
return None
def _main(): def _main():
sha = _run_cmd(["git", "rev-parse", "HEAD"]) sha = _run_cmd(["git", "rev-parse", "HEAD"])
branch = _run_cmd(["git", "rev-parse", "--abbrev-ref", "HEAD"]) branch = _run_cmd(["git", "rev-parse", "--abbrev-ref", "HEAD"])
...@@ -88,17 +128,17 @@ def _main(): ...@@ -88,17 +128,17 @@ def _main():
print("-- Git tag:", tag) print("-- Git tag:", tag)
pytorch_package_dep = _get_pytorch_version() pytorch_package_dep = _get_pytorch_version()
print("-- PyTorch dependency:", pytorch_package_dep) print("-- PyTorch dependency:", pytorch_package_dep)
version = _get_version(sha) version= get_version()
print("-- Building version", version) print("-- Building version", version)
_make_version_file(version, sha) dcu_version = _make_version_file(version)
with open("README.md") as f: with open("README.md") as f:
long_description = f.read() long_description = f.read()
setup( setup(
name="torchaudio", name="torchaudio",
version=version, version=dcu_version,
description="An audio package for PyTorch", description="An audio package for PyTorch",
long_description=long_description, long_description=long_description,
long_description_content_type="text/markdown", long_description_content_type="text/markdown",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment