Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- model_manager.py +35 -5
- requirements.txt +1 -1
model_manager.py
CHANGED
|
@@ -27,12 +27,42 @@ class BitNetManager:
|
|
| 27 |
patched_content = content.replace(old_str, new_str)
|
| 28 |
with open(target_file, "w") as f:
|
| 29 |
f.write(patched_content)
|
| 30 |
-
st.success("Patch applied
|
| 31 |
else:
|
| 32 |
-
st.warning("Patch target line not found
|
| 33 |
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
"""Clone and compile utilizing official setup_env.py with log streaming."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
if not os.path.exists(self.bitnet_dir):
|
| 37 |
st.info("Cloning BitNet repository...")
|
| 38 |
subprocess.run(["git", "clone", "--recursive", self.repo_url], check=True)
|
|
@@ -41,8 +71,8 @@ class BitNetManager:
|
|
| 41 |
|
| 42 |
st.info("Running official BitNet setup (setup_env.py)...")
|
| 43 |
try:
|
| 44 |
-
#
|
| 45 |
-
cmd = ["python", "setup_env.py", "--hf-repo", "1bitLLM/bitnet_b1_58-3B", "--use-pretuned"]
|
| 46 |
|
| 47 |
# Stream the stdout to Streamlit in real-time
|
| 48 |
process = subprocess.Popen(cmd, cwd=self.bitnet_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1)
|
|
|
|
| 27 |
patched_content = content.replace(old_str, new_str)
|
| 28 |
with open(target_file, "w") as f:
|
| 29 |
f.write(patched_content)
|
| 30 |
+
st.success("Patch applied to ggml-bitnet-mad.cpp!")
|
| 31 |
else:
|
| 32 |
+
st.warning("Patch target line not found in ggml-bitnet-mad.cpp.")
|
| 33 |
|
| 34 |
+
# Patch setup_env.py to handle missing huggingface-cli command
|
| 35 |
+
setup_script = os.path.join(self.bitnet_dir, "setup_env.py")
|
| 36 |
+
if os.path.exists(setup_script):
|
| 37 |
+
st.info("Patching setup_env.py to handle path issues...")
|
| 38 |
+
with open(setup_script, "r") as f:
|
| 39 |
+
setup_content = f.read()
|
| 40 |
+
|
| 41 |
+
# Replace literal "huggingface-cli" with the python module call
|
| 42 |
+
# This is safer in environments where the CLI isn't in the global PATH
|
| 43 |
+
old_cli = '"huggingface-cli"'
|
| 44 |
+
new_cli = '"python", "-m", "huggingface_hub.commands.huggingface_cli"'
|
| 45 |
+
|
| 46 |
+
if old_cli in setup_content:
|
| 47 |
+
# We need to be careful with the list structure.
|
| 48 |
+
# setup_env.py usually uses subprocess.run(["huggingface-cli", ...])
|
| 49 |
+
patched_setup = setup_content.replace(old_cli, new_cli)
|
| 50 |
+
with open(setup_script, "w") as f:
|
| 51 |
+
f.write(patched_setup)
|
| 52 |
+
st.success("Patch applied to setup_env.py!")
|
| 53 |
+
elif 'huggingface-cli' in setup_content:
|
| 54 |
+
# Catch cases without quotes if any
|
| 55 |
+
patched_setup = setup_content.replace('huggingface-cli', 'python -m huggingface_hub.commands.huggingface_cli')
|
| 56 |
+
with open(setup_script, "w") as f:
|
| 57 |
+
f.write(patched_setup)
|
| 58 |
+
st.success("Patch applied to setup_env.py (unquoted)!")
|
| 59 |
"""Clone and compile utilizing official setup_env.py with log streaming."""
|
| 60 |
+
# Check if already compiled
|
| 61 |
+
binary = self.get_binary_path()
|
| 62 |
+
if binary and os.path.exists(binary):
|
| 63 |
+
st.success("BitNet engine is already compiled and ready!")
|
| 64 |
+
return True
|
| 65 |
+
|
| 66 |
if not os.path.exists(self.bitnet_dir):
|
| 67 |
st.info("Cloning BitNet repository...")
|
| 68 |
subprocess.run(["git", "clone", "--recursive", self.repo_url], check=True)
|
|
|
|
| 71 |
|
| 72 |
st.info("Running official BitNet setup (setup_env.py)...")
|
| 73 |
try:
|
| 74 |
+
# -u for unbuffered output to see logs in real-time
|
| 75 |
+
cmd = ["python", "-u", "setup_env.py", "--hf-repo", "1bitLLM/bitnet_b1_58-3B", "--use-pretuned"]
|
| 76 |
|
| 77 |
# Stream the stdout to Streamlit in real-time
|
| 78 |
process = subprocess.Popen(cmd, cwd=self.bitnet_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1)
|
requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
streamlit
|
| 2 |
-
huggingface_hub
|
| 3 |
numpy
|
| 4 |
pandas
|
| 5 |
psutil
|
|
|
|
| 1 |
streamlit
|
| 2 |
+
huggingface_hub[cli]
|
| 3 |
numpy
|
| 4 |
pandas
|
| 5 |
psutil
|