From e573b9ebe72d3f60793f5f2551def0fc02cff883 Mon Sep 17 00:00:00 2001 From: Niels Geens Date: Wed, 2 Apr 2025 14:42:35 +0200 Subject: [PATCH] Removed flash-attn as dependency because it's hard to install properly --- Dockerfile | 10 +-- pyproject.toml | 31 -------- scripts/add_to_environment.sh | 15 ---- scripts/bootstrap.sh | 4 - scripts/install.sh | 23 +++--- scripts/local.sh | 5 ++ scripts/restart.sh | 2 - scripts/setup_binaries.py | 75 +++++++++++++++++-- setup.py | 29 +++++++ .../train => sia/llm_engine}/qwq_infer.ipynb | 0 sia/llm_engine/qwq_llm_engine.py | 1 - tools/itb/setup.py | 62 +++++++-------- tools/train/setup.py | 8 +- 13 files changed, 147 insertions(+), 118 deletions(-) delete mode 100644 pyproject.toml delete mode 100755 scripts/add_to_environment.sh create mode 100644 setup.py rename {tools/train/train => sia/llm_engine}/qwq_infer.ipynb (100%) diff --git a/Dockerfile b/Dockerfile index b3c02fe..e8d0ed8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -70,13 +70,7 @@ COPY --from=train-env /root/venvs/train /root/venvs/train COPY --from=sia-env /root/venvs/sia /root/venvs/sia COPY --from=web-build /app/dist /root/static/ -RUN for venv in /root/venvs/*/bin; do \ - echo "export PATH=\"$venv:\$PATH\"" >> /etc/profile.d/sia.sh ; \ -done -RUN for venv in /root/venvs/*/bin; do \ - echo "export PATH=\"$venv:\$PATH\"" > "/etc/profile.d/venv_$(basename "$(dirname "$venv")").sh" \ -done WORKDIR /root/desktop -ENTRYPOINT ["/bin/bash", "-l", "-c"] -CMD ["/root/sia/scripts/restart.sh"] \ No newline at end of file +ENTRYPOINT ["/bin/bash", "-c"] +CMD ["/root/sia/scripts/install.sh; /bin/bash -lc /root/sia/scripts/restart.sh"] diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index d83c899..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,31 +0,0 @@ -[build-system] -requires = ["setuptools>=78", "wheel>=0.45.0", "packaging>=24.0"] -build-backend = "setuptools.build_meta" - -[project] -name = "sia" -version = "0.1.0" -requires-python = ">=3.10" -dependencies = [ - "accelerate>=0.26.0", - "aiohttp>=3.8.0", - "bitsandbytes>=0.41.0", - "dotenv-python>=0.0.1", - "flash-attn>=2.0.0", - "huggingface_hub>=0.16.0", - "lxml>=4.9.0", - "mistral-common>=1.0.0", - "mistralai>=0.0.7", - "openai>=1.0.0", - "psutil>=5.9.0", - "python-dotenv>=1.0.0", - "tiktoken>=0.4.0", - "torch>=2.0.0", - "transformers>=4.30.0" -] - -[project.scripts] -sia = "sia.__main__:main" - -[tool.setuptools] -packages = ["sia"] \ No newline at end of file diff --git a/scripts/add_to_environment.sh b/scripts/add_to_environment.sh deleted file mode 100755 index 0d928b1..0000000 --- a/scripts/add_to_environment.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -local path="$1" -# Check if the path is already in the environment file -if ! grep -q "$path" /etc/environment; then - # Get current PATH from environment file - current_path=$(grep "^PATH=" /etc/environment | cut -d'"' -f2) - - if [ -z "$current_path" ]; then - # If PATH doesn't exist in the file, create it - echo "PATH=\"\$PATH:$path\"" >> /etc/environment - else - # Replace existing PATH line with updated one - sed -i "s|^PATH=.*|PATH=\"$path:$current_path\"|" /etc/environment - fi -fi \ No newline at end of file diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index ef41e4f..8d14cab 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -39,10 +39,6 @@ if [ ! -d "/root/sia" ]; then git config --global core.editor vim fi -# Fixing permissions -echo "Fixing permissions..." -chmod +x /root/sia/scripts/*.sh - # Install Node.js if needed if ! command -v node &> /dev/null; then echo "Installing Node.js..." diff --git a/scripts/install.sh b/scripts/install.sh index 5b1e628..90288aa 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,17 +1,22 @@ #!/bin/bash echo "Installing ITB tool..." -python3 -m venv "/root/venvs/itb" -/root/venvs/itb/bin/pip install -e /root/sia/tools/itb/ -/root/sia/scripts/add_to_environment.sh "/root/venvs/itb/bin" +python3 -m venv /root/venvs/itb +/root/venvs/itb/bin/pip install -e /root/sia/tools/itb +/root/venvs/train/bin/ipython kernel install --name=itb +echo "PATH=\$PATH:/root/venvs/itb/bin" > /etc/profile.d/itb.sh +source /etc/profile.d/itb.sh echo "Installing Train tool..." -python3 -m venv "/root/venvs/train" -/root/venvs/train/bin/pip install -e /root/sia/tools/train/ +python3 -m venv /root/venvs/train +/root/venvs/train/bin/pip install -e /root/sia/tools/train /root/venvs/train/bin/ipython kernel install --name=train -/root/sia/scripts/add_to_environment.sh "/root/venvs/train/bin" +echo "PATH=\$PATH:/root/venvs/train/bin" > /etc/profile.d/train.sh +source /etc/profile.d/train.sh echo "Installing SIA core..." -python3 -m venv "/root/venvs/sia" -/root/venvs/sia/bin/pip install -e /root/sia/ -/root/sia/scripts/add_to_environment.sh "/root/venvs/sia/bin" \ No newline at end of file +python3 -m venv /root/venvs/sia +/root/venvs/sia/bin/pip install -e /root/sia +/root/venvs/train/bin/ipython kernel install --name=sia +echo "PATH=\$PATH:/root/venvs/sia/bin" > /etc/profile.d/sia.sh +source /etc/profile.d/sia.sh diff --git a/scripts/local.sh b/scripts/local.sh index d0a879c..9efdc3b 100755 --- a/scripts/local.sh +++ b/scripts/local.sh @@ -10,7 +10,12 @@ function chown_iterations() { fi } +function clean_docker() { + docker images -f "dangling=true" -q | xargs -r docker rmi +} + trap chown_iterations EXIT +trap clean_docker EXIT docker build \ --tag sia \ diff --git a/scripts/restart.sh b/scripts/restart.sh index 0534205..437f1b1 100755 --- a/scripts/restart.sh +++ b/scripts/restart.sh @@ -2,9 +2,7 @@ set -e -cd "/root/desktop" while true; do - "/root/sia/scripts/install.sh" sia EXIT_CODE=$? diff --git a/scripts/setup_binaries.py b/scripts/setup_binaries.py index d83711a..01ae569 100644 --- a/scripts/setup_binaries.py +++ b/scripts/setup_binaries.py @@ -6,7 +6,63 @@ Usage: setup_binaries.py /path/to/setup.py import os import sys -import re +import ast + + +class SetupVisitor(ast.NodeVisitor): + """AST visitor that finds setup() function calls and extracts scripts.""" + + def __init__(self): + self.scripts = [] + + def visit_Call(self, node): + # Check if this is a call to setup() + if getattr(node.func, 'id', None) == 'setup': + # Look through keyword arguments for scripts + for kw in node.keywords: + if kw.arg == 'scripts': + self._extract_scripts(kw.value) + # Also check entry_points which might contain console_scripts + elif kw.arg == 'entry_points': + self._extract_entry_points(kw.value) + + # Continue traversing the AST + self.generic_visit(node) + + def _extract_scripts(self, node): + """Extract script paths from a list or list comprehension.""" + if isinstance(node, ast.List): + for elt in node.elts: + if isinstance(elt, ast.Str): + if elt.s.startswith('bin/'): + self.scripts.append(elt.s) + # Handle variables and other expressions by looking for string literals + else: + # This is a simple fallback for complex expressions + script_finder = StringLiteralFinder('bin/') + script_finder.visit(node) + self.scripts.extend(script_finder.matching_strings) + + + def _extract_entry_points(self, node): + """Extract console_scripts from entry_points argument.""" + # This would need more complex parsing based on how entry_points is specified + # Often it's a dict with 'console_scripts' key or a string with [console_scripts] section + # For this example, we'll just log that we found it + pass + + +class StringLiteralFinder(ast.NodeVisitor): + """Find string literals that start with a specific prefix.""" + + def __init__(self, prefix): + self.prefix = prefix + self.matching_strings = [] + + def visit_Str(self, node): + if node.s.startswith(self.prefix): + self.matching_strings.append(node.s) + def extract_setup_binaries(setup_path): """Extract binary names from a setup.py file and create placeholder files.""" @@ -15,15 +71,20 @@ def extract_setup_binaries(setup_path): with open(setup_path, 'r') as f: setup_content = f.read() - # Find all references to scripts in bin/ directory - scripts = re.findall(r"'bin/[^']+?'|\"bin/[^\"]+?\"", setup_content) + # Parse the file + tree = ast.parse(setup_content) + + # Find setup() calls and extract scripts + visitor = SetupVisitor() + visitor.visit(tree) + + # Get the scripts + scripts = visitor.scripts + if not scripts: print(f"No bin scripts found in {setup_path}") return True # Not an error, just no scripts - # Clean up the extracted script names - scripts = [script.strip('\'"') for script in scripts] - # Create placeholder files base_dir = os.path.dirname(setup_path) created_count = 0 @@ -61,4 +122,4 @@ if __name__ == "__main__": sys.exit(1) success = extract_setup_binaries(setup_path) - sys.exit(0 if success else 1) \ No newline at end of file + sys.exit(0 if success else 1) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..ddbe62d --- /dev/null +++ b/setup.py @@ -0,0 +1,29 @@ +from setuptools import setup, find_packages + +setup( + name="sia", + version="0.1.0", + packages=find_packages(), + entry_points={ + 'console_scripts': [ + 'sia=sia.__main__:main', + ], + }, + install_requires=[ + 'torch>=2.0.0', + 'accelerate>=0.26.0', + 'aiohttp>=3.8.0', + 'bitsandbytes>=0.41.0', + 'dotenv-python>=0.0.1', + 'huggingface_hub>=0.16.0', + 'lxml>=4.9.0', + 'mistral-common>=1.0.0', + 'mistralai>=0.0.7', + 'openai>=1.0.0', + 'psutil>=5.9.0', + 'python-dotenv>=1.0.0', + 'tiktoken>=0.4.0', + 'transformers>=4.30.0', + ], + python_requires='>=3.10', +) \ No newline at end of file diff --git a/tools/train/train/qwq_infer.ipynb b/sia/llm_engine/qwq_infer.ipynb similarity index 100% rename from tools/train/train/qwq_infer.ipynb rename to sia/llm_engine/qwq_infer.ipynb diff --git a/sia/llm_engine/qwq_llm_engine.py b/sia/llm_engine/qwq_llm_engine.py index dbb9410..e926e73 100644 --- a/sia/llm_engine/qwq_llm_engine.py +++ b/sia/llm_engine/qwq_llm_engine.py @@ -37,7 +37,6 @@ class QwQLlmEngine(LlmEngine): model_path, return_dict=True, device_map="auto", - attn_implementation="flash_attention_2", use_cache=True, quantization_config=quantization_config, ) diff --git a/tools/itb/setup.py b/tools/itb/setup.py index f6e2285..b62ba50 100644 --- a/tools/itb/setup.py +++ b/tools/itb/setup.py @@ -1,34 +1,28 @@ -from setuptools import setup, find_packages - -setup( - name="itb", - version="0.1.0", - packages=find_packages(), - scripts=[ - 'bin/itb_click', - 'bin/itb_cursor', - 'bin/itb_input', - 'bin/itb_navigate', - 'bin/itb_refresh', - 'bin/itb_screenshot', - 'bin/itb_scroll', - 'bin/itb_start' - ], - install_requires=[ - 'selenium>=4.0.0', - 'webdriver-manager>=3.8.0', - 'click>=8.0.0', - 'beautifulsoup4>=4.9.0', - 'pytest>=7.0.0', - 'pytest-cov>=4.0.0', - 'black>=22.0.0', - 'flake8>=4.0.0' - ], - classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.10', - ], - python_requires='>=3.10', -) \ No newline at end of file +from setuptools import setup, find_packages + +setup( + name="itb", + version="0.1.0", + packages=find_packages(), + scripts=[ + 'bin/itb_click', + 'bin/itb_cursor', + 'bin/itb_input', + 'bin/itb_navigate', + 'bin/itb_refresh', + 'bin/itb_screenshot', + 'bin/itb_scroll', + 'bin/itb_start' + ], + install_requires=[ + 'selenium>=4.0.0', + 'webdriver-manager>=3.8.0', + 'click>=8.0.0', + 'beautifulsoup4>=4.9.0', + 'pytest>=7.0.0', + 'pytest-cov>=4.0.0', + 'black>=22.0.0', + 'flake8>=4.0.0' + ], + python_requires='>=3.10', +) diff --git a/tools/train/setup.py b/tools/train/setup.py index e79b8ee..e54266d 100644 --- a/tools/train/setup.py +++ b/tools/train/setup.py @@ -30,11 +30,5 @@ setup( 'unsloth>=2025.3', 'vllm>=0.8', ], - classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.10', - ], python_requires='>=3.10', -) \ No newline at end of file +)