Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- model_manager.py +23 -26
- requirements.txt +3 -0
model_manager.py
CHANGED
|
@@ -11,38 +11,35 @@ class BitNetManager:
|
|
| 11 |
self.build_dir = os.path.join(self.bitnet_dir, "build")
|
| 12 |
|
| 13 |
def setup_engine(self):
|
| 14 |
-
"""Clone and compile
|
| 15 |
if not os.path.exists(self.bitnet_dir):
|
| 16 |
st.info("Cloning BitNet repository...")
|
| 17 |
subprocess.run(["git", "clone", "--recursive", self.repo_url], check=True)
|
| 18 |
|
| 19 |
-
# We
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
st.info("
|
| 28 |
-
|
| 29 |
-
if res_cmake.returncode != 0:
|
| 30 |
-
st.error(f"CMake failed with return code {res_cmake.returncode}")
|
| 31 |
-
st.code(res_cmake.stderr)
|
| 32 |
-
return False
|
| 33 |
-
|
| 34 |
-
st.info("Building project...")
|
| 35 |
-
res_build = subprocess.run(["cmake", "--build", ".", "--config", "Release"], cwd=self.build_dir, capture_output=True, text=True)
|
| 36 |
-
if res_build.returncode != 0:
|
| 37 |
-
st.error(f"Build failed with return code {res_build.returncode}")
|
| 38 |
-
st.code(res_build.stderr)
|
| 39 |
-
return False
|
| 40 |
-
|
| 41 |
-
st.success("Compilation successful!")
|
| 42 |
-
except Exception as e:
|
| 43 |
-
st.error(f"Execution error: {e}")
|
| 44 |
return False
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
def download_model(self, model_id="microsoft/bitnet-b1.58-3B", filename="ggml-model-i2_s.gguf"):
|
| 48 |
"""Download model weights from Hugging Face."""
|
|
|
|
| 11 |
self.build_dir = os.path.join(self.bitnet_dir, "build")
|
| 12 |
|
| 13 |
def setup_engine(self):
|
| 14 |
+
"""Clone and compile utilizing official setup_env.py."""
|
| 15 |
if not os.path.exists(self.bitnet_dir):
|
| 16 |
st.info("Cloning BitNet repository...")
|
| 17 |
subprocess.run(["git", "clone", "--recursive", self.repo_url], check=True)
|
| 18 |
|
| 19 |
+
# We'll use the official setup_env.py which handles kernel injection
|
| 20 |
+
st.info("Running official BitNet setup/compilation (setup_env.py)...")
|
| 21 |
+
try:
|
| 22 |
+
# We pass a model ID to trigger the full build and conversion sequence
|
| 23 |
+
# --md specifies the model, --skip_download if we want to handle it ourselves
|
| 24 |
+
# But letting setup_env.py handle it is safer for dependencies
|
| 25 |
+
cmd = ["python", "setup_env.py", "--md", "microsoft/bitnet-b1.58-3B"]
|
| 26 |
+
|
| 27 |
+
# Use Popen to stream logs to streamlit if possible, or just run and capture
|
| 28 |
+
st.warning("This process injects custom 1-bit kernels and compiles the engine. Please wait...")
|
| 29 |
+
process = subprocess.run(cmd, cwd=self.bitnet_dir, capture_output=True, text=True)
|
| 30 |
|
| 31 |
+
if process.returncode != 0:
|
| 32 |
+
st.error(f"Official Setup failed (Exit {process.returncode})")
|
| 33 |
+
st.code(process.stderr)
|
| 34 |
+
st.info("Detailed Log:")
|
| 35 |
+
st.code(process.stdout[-2000:]) # Show last 2000 chars of progress
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
return False
|
| 37 |
+
|
| 38 |
+
st.success("Official Setup Completed Successfully!")
|
| 39 |
+
return True
|
| 40 |
+
except Exception as e:
|
| 41 |
+
st.error(f"Execution error during setup: {e}")
|
| 42 |
+
return False
|
| 43 |
|
| 44 |
def download_model(self, model_id="microsoft/bitnet-b1.58-3B", filename="ggml-model-i2_s.gguf"):
|
| 45 |
"""Download model weights from Hugging Face."""
|
requirements.txt
CHANGED
|
@@ -3,3 +3,6 @@ huggingface_hub
|
|
| 3 |
numpy
|
| 4 |
pandas
|
| 5 |
psutil
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
numpy
|
| 4 |
pandas
|
| 5 |
psutil
|
| 6 |
+
transformers
|
| 7 |
+
tokenizers
|
| 8 |
+
sentencepiece
|