From ef2a8adf23135017fa0afc1524442cfe76787520 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Tue, 2 Apr 2024 17:35:22 -0400 Subject: [PATCH 01/43] modifying tests --- ci/Jenkinsfile | 5 ++-- ci/modify_config_test.py | 6 ----- .../components/multivec_retriever_test.py | 20 ++++++++++++-- .../vectordb/deeplake_client_test.py | 26 +++++++++++++++---- 4 files changed, 42 insertions(+), 15 deletions(-) delete mode 100644 ci/modify_config_test.py diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 56d3551..d0d3f52 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -6,6 +6,7 @@ pipeline { } environment { PYTHONPATH = "${env.WORKSPACE}/.venv/bin" + AUTH_TOKEN = credentials('hf_token') } @@ -35,7 +36,6 @@ pipeline { stage('Config'){ steps{ - sh 'echo $env.JENKINS_HOME' withPythonEnv(PYTHONPATH){ sh 'python3 ci/modify_config.py' sh 'rm -rf $JENKINS_HOME/ci_test_data/data/vectordb/ci_test' @@ -84,7 +84,6 @@ pipeline { stage('Tests'){ steps{ - sh 'echo $USER' sh 'docker pull chromadb/chroma' sh 'docker run -d --name jenkins-chroma -p 8000:8000 chromadb/chroma' withPythonEnv(PYTHONPATH){ @@ -98,6 +97,8 @@ pipeline { withChecks('Integration Tests'){ junit 'pytest-report.xml' } +// sh 'rm -rf $JENKINS_HOME/ci_test_data/data/vectordb/test_retriever' +// sh 'rm -rf $JENKINS_HOME/ci_test_data/data/vectordb/test_client' sh 'docker stop jenkins-chroma' sh 'docker rm jenkins-chroma' diff --git a/ci/modify_config_test.py b/ci/modify_config_test.py deleted file mode 100644 index b93a40a..0000000 --- a/ci/modify_config_test.py +++ /dev/null @@ -1,6 +0,0 @@ -from grag.components.utils import get_config - -config = get_config() -print(f"{config['root']['root_path']=}") -print(f"{config['data']['data_path'] = }") -print(f"{config['llm']['base_dir'] = }") diff --git a/src/tests/components/multivec_retriever_test.py b/src/tests/components/multivec_retriever_test.py index 3f847bd..04d450c 100644 --- a/src/tests/components/multivec_retriever_test.py +++ b/src/tests/components/multivec_retriever_test.py @@ -1,16 +1,32 @@ import json +import os +import subprocess +from pathlib import Path from grag.components.multivec_retriever import Retriever from grag.components.vectordb.deeplake_client import DeepLakeClient from langchain_core.documents import Document -client = DeepLakeClient(collection_name="ci_test") +res = subprocess.run(["echo", "$JENKINS_HOME"], check=True, capture_output=True) +if res.stdout == "JENKINS_HOME": + jenkins_home = os.getenv('JENKINS_HOME') + test_path = Path(jenkins_home) / 'ci_test_data/data/vectordb/test_retriever' + if os.path.exists(test_path): + shutil.rmtree(test_path) + print('Deleting test retriever: {}'.format(test_path)) +else: + test_path = dir_path = Path(__file__).parents[5] / 'data/vectordb/test_retriever' + if os.path.exists(test_path): + shutil.rmtree(test_path) + print('Deleting test retriever: {}'.format(test_path)) + +client = DeepLakeClient(collection_name="test_retriever") retriever = Retriever(vectordb=client) # pass test collection doc = Document(page_content="Hello worlds", metadata={"source": "bars"}) -def test_retriver_id_gen(): +def test_retriever_id_gen(): doc = Document(page_content="Hello world", metadata={"source": "bar"}) id_ = retriever.id_gen(doc) assert isinstance(id, str) diff --git a/src/tests/components/vectordb/deeplake_client_test.py b/src/tests/components/vectordb/deeplake_client_test.py index cea5e61..9a425f5 100644 --- a/src/tests/components/vectordb/deeplake_client_test.py +++ b/src/tests/components/vectordb/deeplake_client_test.py @@ -1,9 +1,25 @@ import asyncio +import os +import subprocess +from pathlib import Path import pytest from grag.components.vectordb.deeplake_client import DeepLakeClient from langchain_core.documents import Document +res = subprocess.run(["echo", "$JENKINS_HOME"], check=True, capture_output=True) +if res.stdout == "JENKINS_HOME": + jenkins_home = os.getenv('JENKINS_HOME') + test_path = Path(jenkins_home) / 'ci_test_data/data/vectordb/test_client' + if os.path.exists(test_path): + shutil.rmtree(test_path) + print('Deleting test retriever: {}'.format(test_path)) +else: + test_path = dir_path = Path(__file__).parents[5] / 'data/vectordb/test_client' + if os.path.exists(test_path): + shutil.rmtree(test_path) + print('Deleting test retriever: {}'.format(test_path)) + def test_deeplake_add_docs(): docs = [ @@ -40,7 +56,7 @@ def test_deeplake_add_docs(): storm-clouds was split to the blinding zigzag of lightning, and the thunder rolled and boomed, like the Colorado in flood.""", ] - deeplake_client = DeepLakeClient(collection_name="test") + deeplake_client = DeepLakeClient(collection_name="test_client") if len(deeplake_client) > 0: deeplake_client.delete() docs = [Document(page_content=doc) for doc in docs] @@ -49,7 +65,7 @@ def test_deeplake_add_docs(): del deeplake_client -def test_chroma_aadd_docs(): +def test_deeplake_aadd_docs(): docs = [ """And so on this rainbow day, with storms all around them, and blue sky above, they rode only as far as the valley. But from there, before they @@ -84,7 +100,7 @@ def test_chroma_aadd_docs(): storm-clouds was split to the blinding zigzag of lightning, and the thunder rolled and boomed, like the Colorado in flood.""", ] - deeplake_client = DeepLakeClient(collection_name="test") + deeplake_client = DeepLakeClient(collection_name="test_client") if len(deeplake_client) > 0: deeplake_client.delete() docs = [Document(page_content=doc) for doc in docs] @@ -108,7 +124,7 @@ def test_deeplake_get_chunk(top_k, with_score): ankles from Joel Creech's lasso had never mended. The girl was unutterably happy, but it was possible that she would never race a horse again.""" - deeplake_client = DeepLakeClient(collection_name="test", read_only=True) + deeplake_client = DeepLakeClient(collection_name="test_client", read_only=True) retrieved_chunks = deeplake_client.get_chunk( query=query, top_k=top_k, with_score=with_score ) @@ -132,7 +148,7 @@ def test_deeplake_aget_chunk(top_k, with_score): ankles from Joel Creech's lasso had never mended. The girl was unutterably happy, but it was possible that she would never race a horse again.""" - deeplake_client = DeepLakeClient(collection_name="test", read_only=True) + deeplake_client = DeepLakeClient(collection_name="test_client", read_only=True) loop = asyncio.get_event_loop() retrieved_chunks = loop.run_until_complete( deeplake_client.aget_chunk(query=query, top_k=top_k, with_score=with_score) From e9a190055392e9bc33de279e5cd66e9f3fd493ce Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Tue, 2 Apr 2024 18:34:35 -0400 Subject: [PATCH 02/43] added BLAS for jenkins --- ci/Jenkinsfile | 5 +++-- src/grag/components/utils.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index d0d3f52..84cb098 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -28,7 +28,8 @@ pipeline { stage('Install dependencies'){ steps { withPythonEnv(PYTHONPATH){ - sh "pip install -e ." + sh 'pip install -e .' + sh 'CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir' } } @@ -89,7 +90,7 @@ pipeline { withPythonEnv(PYTHONPATH){ sh 'pip install pytest' sh 'python3 ci/unlock_deeplake.py' - sh 'pytest src --junitxml=pytest-report.xml' + sh 'pytest src -vvv --junitxml=pytest-report.xml' } } post { diff --git a/src/grag/components/utils.py b/src/grag/components/utils.py index 491c9ec..2dcc14f 100644 --- a/src/grag/components/utils.py +++ b/src/grag/components/utils.py @@ -42,7 +42,7 @@ def find_config_path(current_path: Path) -> Path: Raises: FileNotFoundError: If 'config.ini' cannot be found in any of the parent directories. """ - config_path = Path("src/config.ini") + config_path = Path("config.ini") while not (current_path / config_path).exists(): current_path = current_path.parent if current_path == current_path.parent: From c39203b323f823676de5018680ecf4fff31cfa89 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Tue, 2 Apr 2024 18:47:23 -0400 Subject: [PATCH 03/43] adding BLAS --- ci/Jenkinsfile | 2 +- src/tests/components/multivec_retriever_test.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 84cb098..1b1e2c2 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -29,7 +29,7 @@ pipeline { steps { withPythonEnv(PYTHONPATH){ sh 'pip install -e .' - sh 'CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir' + sh 'CMAKE_ARGS="-DLLAMA_CUDA=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir' } } diff --git a/src/tests/components/multivec_retriever_test.py b/src/tests/components/multivec_retriever_test.py index 04d450c..4d66bc1 100644 --- a/src/tests/components/multivec_retriever_test.py +++ b/src/tests/components/multivec_retriever_test.py @@ -29,7 +29,7 @@ def test_retriever_id_gen(): doc = Document(page_content="Hello world", metadata={"source": "bar"}) id_ = retriever.id_gen(doc) - assert isinstance(id, str) + assert isinstance(id_, str) assert len(id_) == 32 doc.page_content = doc.page_content + 'ABC' id_1 = retriever.id_gen(doc) @@ -95,7 +95,7 @@ def test_retriever_add_docs(): assert len(retrieved) == len(ids) for i, doc in enumerate(docs): retrieved_doc = json.loads(retrieved[i].decode()) - assert doc.metadata == retrieved_doc.metadata + assert doc.metadata == retrieved_doc['metadata'] def test_retriever_aadd_docs(): From 3e56298012a0ecce1bb58fc980720b8da0dd3de3 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Tue, 2 Apr 2024 19:05:51 -0400 Subject: [PATCH 04/43] adding CUDA path explicitly in environment --- ci/Jenkinsfile | 19 ++++++++++--------- src/grag/components/multivec_retriever.py | 1 + .../components/multivec_retriever_test.py | 8 +++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 1b1e2c2..e49ec99 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -7,6 +7,7 @@ pipeline { environment { PYTHONPATH = "${env.WORKSPACE}/.venv/bin" AUTH_TOKEN = credentials('hf_token') + CUDACXX = '/usr/local/cuda-12/bin/nvcc' } @@ -14,7 +15,7 @@ pipeline { stage('Checkout') { steps { - cleanWs() +// cleanWs() checkout scm } } @@ -103,14 +104,14 @@ pipeline { sh 'docker stop jenkins-chroma' sh 'docker rm jenkins-chroma' - cleanWs( - cleanWhenNotBuilt: false, - deleteDirs: true, - disableDeferredWipeout: true, - notFailBuild: true, - patterns: [[pattern: '.gitignore', type: 'INCLUDE'], - [pattern: '.propsfile', type: 'EXCLUDE']] - ) +// cleanWs( +// cleanWhenNotBuilt: false, +// deleteDirs: true, +// disableDeferredWipeout: true, +// notFailBuild: true, +// patterns: [[pattern: '.gitignore', type: 'INCLUDE'], +// [pattern: '.propsfile', type: 'EXCLUDE']] +// ) } } } diff --git a/src/grag/components/multivec_retriever.py b/src/grag/components/multivec_retriever.py index 41bff2d..dd9d240 100644 --- a/src/grag/components/multivec_retriever.py +++ b/src/grag/components/multivec_retriever.py @@ -78,6 +78,7 @@ def __init__( byte_store=self.store, # type: ignore id_key=self.id_key, ) + self.docstore = self.retriever.docstore self.splitter = TextSplitter() self.top_k: int = top_k self.retriever.search_kwargs = {"k": self.top_k} diff --git a/src/tests/components/multivec_retriever_test.py b/src/tests/components/multivec_retriever_test.py index 4d66bc1..bf2f54a 100644 --- a/src/tests/components/multivec_retriever_test.py +++ b/src/tests/components/multivec_retriever_test.py @@ -1,4 +1,3 @@ -import json import os import subprocess from pathlib import Path @@ -91,11 +90,10 @@ def test_retriever_add_docs(): ] ids = retriever.gen_doc_ids(docs) retriever.add_docs(docs) - retrieved = retriever.store.mget(ids) + retrieved = retriever.docstore.mget(ids) assert len(retrieved) == len(ids) - for i, doc in enumerate(docs): - retrieved_doc = json.loads(retrieved[i].decode()) - assert doc.metadata == retrieved_doc['metadata'] + for ret, doc in zip(retrieved, docs): + assert ret.metadata == doc.metadata def test_retriever_aadd_docs(): From a6a63368b549cdd9f8a3a8cc5b5cf91a43167557 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Tue, 2 Apr 2024 19:42:46 -0400 Subject: [PATCH 05/43] .env loading in config --- ci/Jenkinsfile | 4 +++- src/config.ini | 3 +++ src/grag/components/utils.py | 6 ++++-- src/tests/quantize/quantize_test.py | 3 +++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index e49ec99..7eee484 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -8,6 +8,7 @@ pipeline { PYTHONPATH = "${env.WORKSPACE}/.venv/bin" AUTH_TOKEN = credentials('hf_token') CUDACXX = '/usr/local/cuda-12/bin/nvcc' + CMAKE_ARGS = "-DLLAMA_CUDA=on" } @@ -30,7 +31,7 @@ pipeline { steps { withPythonEnv(PYTHONPATH){ sh 'pip install -e .' - sh 'CMAKE_ARGS="-DLLAMA_CUDA=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir' +// sh 'CMAKE_ARGS="-DLLAMA_CUDA=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir' } } @@ -39,6 +40,7 @@ pipeline { stage('Config'){ steps{ withPythonEnv(PYTHONPATH){ + sh 'cp $JENKINS_HOME/hf_token' sh 'python3 ci/modify_config.py' sh 'rm -rf $JENKINS_HOME/ci_test_data/data/vectordb/ci_test' sh 'cp -r $JENKINS_HOME/ci_test_data/data/backup_vectordb/ci_test $JENKINS_HOME/ci_test_data/data/vectordb' diff --git a/src/config.ini b/src/config.ini index 1760277..1f96419 100644 --- a/src/config.ini +++ b/src/config.ini @@ -58,6 +58,9 @@ table_as_html : True [data] data_path : ${root:root_path}/data +[env] +env_path : ${root:root_path}/.env + [root] root_path : /home/ubuntu/volume_2k/Capstone_5 diff --git a/src/grag/components/utils.py b/src/grag/components/utils.py index 2dcc14f..509ecb3 100644 --- a/src/grag/components/utils.py +++ b/src/grag/components/utils.py @@ -12,6 +12,7 @@ from pathlib import Path from typing import List +from dotenv import load_dotenv from langchain_core.documents import Document @@ -67,9 +68,10 @@ def get_config() -> ConfigParser: else: config_path = find_config_path(script_location) os.environ["CONFIG_PATH"] = str(config_path) - print(f"Loaded config from {config_path}.") + # Initialize parser and read config config = ConfigParser(interpolation=ExtendedInterpolation()) config.read(config_path) - + print(f"Loaded config from {config_path}.") + load_dotenv(config['env']['env_path']) return config diff --git a/src/tests/quantize/quantize_test.py b/src/tests/quantize/quantize_test.py index af0e9dd..68078fe 100644 --- a/src/tests/quantize/quantize_test.py +++ b/src/tests/quantize/quantize_test.py @@ -1,4 +1,5 @@ import os +import shutil from pathlib import Path from grag.quantize.utils import ( @@ -9,6 +10,8 @@ ) root_path = Path(__file__).parent / "test_data" +if os.path.exists(root_path): + shutil.rmtree(root_path) os.makedirs(root_path, exist_ok=True) From 8d2a2bbb95e86b635459703367e685f5c6b893a6 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Tue, 2 Apr 2024 19:43:38 -0400 Subject: [PATCH 06/43] . --- ci/Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 7eee484..8bd7cd5 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -40,7 +40,6 @@ pipeline { stage('Config'){ steps{ withPythonEnv(PYTHONPATH){ - sh 'cp $JENKINS_HOME/hf_token' sh 'python3 ci/modify_config.py' sh 'rm -rf $JENKINS_HOME/ci_test_data/data/vectordb/ci_test' sh 'cp -r $JENKINS_HOME/ci_test_data/data/backup_vectordb/ci_test $JENKINS_HOME/ci_test_data/data/vectordb' From ed18d766d2e223713fe110c1ba180078c7bf525c Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Tue, 2 Apr 2024 19:48:07 -0400 Subject: [PATCH 07/43] removing load_dotenv --- src/grag/components/llm.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/grag/components/llm.py b/src/grag/components/llm.py index 54f14e8..53cebef 100644 --- a/src/grag/components/llm.py +++ b/src/grag/components/llm.py @@ -4,7 +4,6 @@ from pathlib import Path import torch -from dotenv import load_dotenv from langchain.callbacks.manager import CallbackManager from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler from langchain_community.llms import LlamaCpp @@ -117,7 +116,7 @@ def hf_pipeline(self, is_local=False): ) except OSError: # LocalTokenNotFoundError: # If loading fails due to an auth token error, then load the token and retry - load_dotenv() + # load_dotenv() auth_token = os.getenv("AUTH_TOKEN") if not auth_token: raise ValueError("Authentication token not provided.") From 5057981ffbcd19945ccdb366ba9e08b1fee8fde1 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Tue, 2 Apr 2024 20:20:05 -0400 Subject: [PATCH 08/43] removing test data --- ci/Jenkinsfile | 18 +++++----- .../components/multivec_retriever_test.py | 29 ++++++++-------- .../vectordb/deeplake_client_test.py | 33 +++++++++++-------- 3 files changed, 43 insertions(+), 37 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 8bd7cd5..34f1aad 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -16,7 +16,7 @@ pipeline { stage('Checkout') { steps { -// cleanWs() + cleanWs() checkout scm } } @@ -105,14 +105,14 @@ pipeline { sh 'docker stop jenkins-chroma' sh 'docker rm jenkins-chroma' -// cleanWs( -// cleanWhenNotBuilt: false, -// deleteDirs: true, -// disableDeferredWipeout: true, -// notFailBuild: true, -// patterns: [[pattern: '.gitignore', type: 'INCLUDE'], -// [pattern: '.propsfile', type: 'EXCLUDE']] -// ) + cleanWs( + cleanWhenNotBuilt: false, + deleteDirs: true, + disableDeferredWipeout: true, + notFailBuild: true, + patterns: [[pattern: '.gitignore', type: 'INCLUDE'], + [pattern: '.propsfile', type: 'EXCLUDE']] + ) } } } diff --git a/src/tests/components/multivec_retriever_test.py b/src/tests/components/multivec_retriever_test.py index bf2f54a..c686a21 100644 --- a/src/tests/components/multivec_retriever_test.py +++ b/src/tests/components/multivec_retriever_test.py @@ -1,23 +1,24 @@ import os -import subprocess -from pathlib import Path from grag.components.multivec_retriever import Retriever +from grag.components.utils import get_config from grag.components.vectordb.deeplake_client import DeepLakeClient from langchain_core.documents import Document -res = subprocess.run(["echo", "$JENKINS_HOME"], check=True, capture_output=True) -if res.stdout == "JENKINS_HOME": - jenkins_home = os.getenv('JENKINS_HOME') - test_path = Path(jenkins_home) / 'ci_test_data/data/vectordb/test_retriever' - if os.path.exists(test_path): - shutil.rmtree(test_path) - print('Deleting test retriever: {}'.format(test_path)) -else: - test_path = dir_path = Path(__file__).parents[5] / 'data/vectordb/test_retriever' - if os.path.exists(test_path): - shutil.rmtree(test_path) - print('Deleting test retriever: {}'.format(test_path)) +# res = subprocess.run(["echo", "$JENKINS_HOME"], check=True, capture_output=True) +# if res.stdout == "JENKINS_HOME": +# jenkins_home = os.getenv('JENKINS_HOME') +# test_path = Path(jenkins_home) / 'ci_test_data/data/vectordb/test_retriever' +# if os.path.exists(test_path): +# shutil.rmtree(test_path) +# print('Deleting test retriever: {}'.format(test_path)) +# else: +config = get_config() + +test_path = dir_path = config['data']['data_path'] / 'vectordb/test_retriever' +if os.path.exists(test_path): + shutil.rmtree(test_path) + print('Deleting test retriever: {}'.format(test_path)) client = DeepLakeClient(collection_name="test_retriever") retriever = Retriever(vectordb=client) # pass test collection diff --git a/src/tests/components/vectordb/deeplake_client_test.py b/src/tests/components/vectordb/deeplake_client_test.py index 9a425f5..d92638e 100644 --- a/src/tests/components/vectordb/deeplake_client_test.py +++ b/src/tests/components/vectordb/deeplake_client_test.py @@ -1,24 +1,29 @@ import asyncio import os -import subprocess -from pathlib import Path import pytest +from grag.components.utils import get_config from grag.components.vectordb.deeplake_client import DeepLakeClient from langchain_core.documents import Document -res = subprocess.run(["echo", "$JENKINS_HOME"], check=True, capture_output=True) -if res.stdout == "JENKINS_HOME": - jenkins_home = os.getenv('JENKINS_HOME') - test_path = Path(jenkins_home) / 'ci_test_data/data/vectordb/test_client' - if os.path.exists(test_path): - shutil.rmtree(test_path) - print('Deleting test retriever: {}'.format(test_path)) -else: - test_path = dir_path = Path(__file__).parents[5] / 'data/vectordb/test_client' - if os.path.exists(test_path): - shutil.rmtree(test_path) - print('Deleting test retriever: {}'.format(test_path)) +# res = subprocess.run(["echo", "$JENKINS_HOME"], check=True, capture_output=True) +# if res.stdout == "JENKINS_HOME": +# jenkins_home = os.getenv('JENKINS_HOME') +# test_path = Path(jenkins_home) / 'ci_test_data/data/vectordb/test_client' +# if os.path.exists(test_path): +# shutil.rmtree(test_path) +# print('Deleting test retriever: {}'.format(test_path)) +# else: +# test_path = dir_path = Path(__file__).parents[5] / 'data/vectordb/test_client' +# if os.path.exists(test_path): +# shutil.rmtree(test_path) +# print('Deleting test retriever: {}'.format(test_path)) + +config = get_config() +test_path = dir_path = config['data']['data_path'] / 'vectordb/test_client' +if os.path.exists(test_path): + shutil.rmtree(test_path) + print('Deleting test retriever: {}'.format(test_path)) def test_deeplake_add_docs(): From 4800b7823afcdc234924e727c4f86bb21151e743 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Tue, 2 Apr 2024 20:26:10 -0400 Subject: [PATCH 09/43] . --- ci/Jenkinsfile | 18 +++++++++--------- .../components/multivec_retriever_test.py | 2 +- .../vectordb/deeplake_client_test.py | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 34f1aad..8bd7cd5 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -16,7 +16,7 @@ pipeline { stage('Checkout') { steps { - cleanWs() +// cleanWs() checkout scm } } @@ -105,14 +105,14 @@ pipeline { sh 'docker stop jenkins-chroma' sh 'docker rm jenkins-chroma' - cleanWs( - cleanWhenNotBuilt: false, - deleteDirs: true, - disableDeferredWipeout: true, - notFailBuild: true, - patterns: [[pattern: '.gitignore', type: 'INCLUDE'], - [pattern: '.propsfile', type: 'EXCLUDE']] - ) +// cleanWs( +// cleanWhenNotBuilt: false, +// deleteDirs: true, +// disableDeferredWipeout: true, +// notFailBuild: true, +// patterns: [[pattern: '.gitignore', type: 'INCLUDE'], +// [pattern: '.propsfile', type: 'EXCLUDE']] +// ) } } } diff --git a/src/tests/components/multivec_retriever_test.py b/src/tests/components/multivec_retriever_test.py index c686a21..640e8b8 100644 --- a/src/tests/components/multivec_retriever_test.py +++ b/src/tests/components/multivec_retriever_test.py @@ -15,7 +15,7 @@ # else: config = get_config() -test_path = dir_path = config['data']['data_path'] / 'vectordb/test_retriever' +test_path = Path(config['data']['data_path']) / 'vectordb/test_retriever' if os.path.exists(test_path): shutil.rmtree(test_path) print('Deleting test retriever: {}'.format(test_path)) diff --git a/src/tests/components/vectordb/deeplake_client_test.py b/src/tests/components/vectordb/deeplake_client_test.py index d92638e..aa73b17 100644 --- a/src/tests/components/vectordb/deeplake_client_test.py +++ b/src/tests/components/vectordb/deeplake_client_test.py @@ -20,7 +20,7 @@ # print('Deleting test retriever: {}'.format(test_path)) config = get_config() -test_path = dir_path = config['data']['data_path'] / 'vectordb/test_client' +test_path = Path(config['data']['data_path']) / 'vectordb/test_client' if os.path.exists(test_path): shutil.rmtree(test_path) print('Deleting test retriever: {}'.format(test_path)) From 84675ad5e5ede3bc2312def47f662277f29f4b3a Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Tue, 2 Apr 2024 20:28:09 -0400 Subject: [PATCH 10/43] . --- src/tests/components/multivec_retriever_test.py | 1 + src/tests/components/vectordb/deeplake_client_test.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/tests/components/multivec_retriever_test.py b/src/tests/components/multivec_retriever_test.py index 640e8b8..b101f52 100644 --- a/src/tests/components/multivec_retriever_test.py +++ b/src/tests/components/multivec_retriever_test.py @@ -1,4 +1,5 @@ import os +from pathlib import Path from grag.components.multivec_retriever import Retriever from grag.components.utils import get_config diff --git a/src/tests/components/vectordb/deeplake_client_test.py b/src/tests/components/vectordb/deeplake_client_test.py index aa73b17..26a180d 100644 --- a/src/tests/components/vectordb/deeplake_client_test.py +++ b/src/tests/components/vectordb/deeplake_client_test.py @@ -1,5 +1,6 @@ import asyncio import os +from pathlib import Path import pytest from grag.components.utils import get_config From cf233e7b846b55f502bcce290526bbf6cb6b2f33 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Tue, 2 Apr 2024 20:29:51 -0400 Subject: [PATCH 11/43] . --- src/tests/components/multivec_retriever_test.py | 1 + src/tests/components/vectordb/deeplake_client_test.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/tests/components/multivec_retriever_test.py b/src/tests/components/multivec_retriever_test.py index b101f52..2ac99c0 100644 --- a/src/tests/components/multivec_retriever_test.py +++ b/src/tests/components/multivec_retriever_test.py @@ -1,4 +1,5 @@ import os +import shutil from pathlib import Path from grag.components.multivec_retriever import Retriever diff --git a/src/tests/components/vectordb/deeplake_client_test.py b/src/tests/components/vectordb/deeplake_client_test.py index 26a180d..7e0938d 100644 --- a/src/tests/components/vectordb/deeplake_client_test.py +++ b/src/tests/components/vectordb/deeplake_client_test.py @@ -1,5 +1,6 @@ import asyncio import os +import shutil from pathlib import Path import pytest From b1a5da5faad22d940354226f196165f6bc87d9cf Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Tue, 2 Apr 2024 20:40:51 -0400 Subject: [PATCH 12/43] . --- ci/Jenkinsfile | 22 +++++++++++----------- ci/modify_config.py | 1 + 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 8bd7cd5..20de920 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -8,7 +8,7 @@ pipeline { PYTHONPATH = "${env.WORKSPACE}/.venv/bin" AUTH_TOKEN = credentials('hf_token') CUDACXX = '/usr/local/cuda-12/bin/nvcc' - CMAKE_ARGS = "-DLLAMA_CUDA=on" +// CMAKE_ARGS = "-DLLAMA_CUDA=on" } @@ -16,7 +16,7 @@ pipeline { stage('Checkout') { steps { -// cleanWs() + cleanWs() checkout scm } } @@ -31,7 +31,7 @@ pipeline { steps { withPythonEnv(PYTHONPATH){ sh 'pip install -e .' -// sh 'CMAKE_ARGS="-DLLAMA_CUDA=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir' + sh 'CMAKE_ARGS="-DLLAMA_CUDA=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir' } } @@ -105,14 +105,14 @@ pipeline { sh 'docker stop jenkins-chroma' sh 'docker rm jenkins-chroma' -// cleanWs( -// cleanWhenNotBuilt: false, -// deleteDirs: true, -// disableDeferredWipeout: true, -// notFailBuild: true, -// patterns: [[pattern: '.gitignore', type: 'INCLUDE'], -// [pattern: '.propsfile', type: 'EXCLUDE']] -// ) + cleanWs( + cleanWhenNotBuilt: false, + deleteDirs: true, + disableDeferredWipeout: true, + notFailBuild: true, + patterns: [[pattern: '.gitignore', type: 'INCLUDE'], + [pattern: '.propsfile', type: 'EXCLUDE']] + ) } } } diff --git a/ci/modify_config.py b/ci/modify_config.py index 759e88d..f210f69 100644 --- a/ci/modify_config.py +++ b/ci/modify_config.py @@ -12,6 +12,7 @@ config['root']['root_path'] = f'{workspace}' config['data']['data_path'] = f'{jenkins_home}/ci_test_data/data' config['llm']['base_dir'] = f'{jenkins_home}/ci_test_models/models' +config['env']['env_path'] = f'{jenkins_home}/env_file/.env' with open(f'{workspace}/src/config.ini', 'w') as configfile: config.write(configfile) From 5dd4008af1eedd2e63237049401a67a07f7035ff Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Tue, 2 Apr 2024 21:11:14 -0400 Subject: [PATCH 13/43] . --- src/tests/components/embedding_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/components/embedding_test.py b/src/tests/components/embedding_test.py index 1eda90f..2aecc26 100644 --- a/src/tests/components/embedding_test.py +++ b/src/tests/components/embedding_test.py @@ -47,3 +47,4 @@ def test_embeddings(embedding_config): cosine_similarity(doc_vecs[0], doc_vecs[2]), ] assert similarity_scores[0] > similarity_scores[1] + del embedding From 4ad2de88f1d5a2846c9edbd3cadb51ebc53aba35 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Tue, 2 Apr 2024 21:18:17 -0400 Subject: [PATCH 14/43] . --- ci/Jenkinsfile | 18 +++++++++--------- src/tests/components/llm_test.py | 3 +++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 20de920..3bc1fa7 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -16,7 +16,7 @@ pipeline { stage('Checkout') { steps { - cleanWs() +// cleanWs() checkout scm } } @@ -105,14 +105,14 @@ pipeline { sh 'docker stop jenkins-chroma' sh 'docker rm jenkins-chroma' - cleanWs( - cleanWhenNotBuilt: false, - deleteDirs: true, - disableDeferredWipeout: true, - notFailBuild: true, - patterns: [[pattern: '.gitignore', type: 'INCLUDE'], - [pattern: '.propsfile', type: 'EXCLUDE']] - ) +// cleanWs( +// cleanWhenNotBuilt: false, +// deleteDirs: true, +// disableDeferredWipeout: true, +// notFailBuild: true, +// patterns: [[pattern: '.gitignore', type: 'INCLUDE'], +// [pattern: '.propsfile', type: 'EXCLUDE']] +// ) } } } diff --git a/src/tests/components/llm_test.py b/src/tests/components/llm_test.py index df0f4d9..dbc8c4d 100644 --- a/src/tests/components/llm_test.py +++ b/src/tests/components/llm_test.py @@ -2,6 +2,9 @@ import pytest from grag.components.llm import LLM +from grag.components.utils import get_config + +config = get_config() llama_models = [ "Llama-2-7b-chat", From fff42ab9a4c7e9d68e59735c7b8ca9586bb8b069 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Tue, 2 Apr 2024 21:30:20 -0400 Subject: [PATCH 15/43] . --- ci/Jenkinsfile | 4 ++-- src/tests/components/llm_test.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 3bc1fa7..8bd7cd5 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -8,7 +8,7 @@ pipeline { PYTHONPATH = "${env.WORKSPACE}/.venv/bin" AUTH_TOKEN = credentials('hf_token') CUDACXX = '/usr/local/cuda-12/bin/nvcc' -// CMAKE_ARGS = "-DLLAMA_CUDA=on" + CMAKE_ARGS = "-DLLAMA_CUDA=on" } @@ -31,7 +31,7 @@ pipeline { steps { withPythonEnv(PYTHONPATH){ sh 'pip install -e .' - sh 'CMAKE_ARGS="-DLLAMA_CUDA=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir' +// sh 'CMAKE_ARGS="-DLLAMA_CUDA=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir' } } diff --git a/src/tests/components/llm_test.py b/src/tests/components/llm_test.py index dbc8c4d..39fb420 100644 --- a/src/tests/components/llm_test.py +++ b/src/tests/components/llm_test.py @@ -9,6 +9,7 @@ llama_models = [ "Llama-2-7b-chat", "Llama-2-13b-chat", + "gemma-7b-it", "Mixtral-8x7B-Instruct-v0.1", "gemma-7b-it", ] @@ -18,7 +19,7 @@ # 'mistralai/Mixtral-8x7B-Instruct-v0.1', "google/gemma-7b-it", ] -cpp_quantization = ["Q5_K_M", "Q5_K_M", "Q4_K_M", "f16"] +cpp_quantization = ["Q5_K_M", "Q5_K_M", "f16", "Q4_K_M", "f16"] hf_quantization = ["Q8", "Q4", "Q4"] # , 'Q4'] params = [(model, quant) for model, quant in zip(hf_models, hf_quantization)] From 18d87ba05faef6d4d838fae02b8d9506c4f7c7d0 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Tue, 2 Apr 2024 21:32:15 -0400 Subject: [PATCH 16/43] . --- ci/Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 8bd7cd5..617bafc 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -97,13 +97,14 @@ pipeline { } post { always{ + sh 'docker stop jenkins-chroma' + sh 'docker rm jenkins-chroma' withChecks('Integration Tests'){ junit 'pytest-report.xml' } // sh 'rm -rf $JENKINS_HOME/ci_test_data/data/vectordb/test_retriever' // sh 'rm -rf $JENKINS_HOME/ci_test_data/data/vectordb/test_client' - sh 'docker stop jenkins-chroma' - sh 'docker rm jenkins-chroma' + // cleanWs( // cleanWhenNotBuilt: false, From 8a5db2f412275bd1acaf66b037093b4d01e6c5b5 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 15:00:09 -0400 Subject: [PATCH 17/43] gemma issue --- ci/Jenkinsfile | 20 ++++++++++---------- src/tests/components/llm_test.py | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 617bafc..8506a66 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -8,7 +8,7 @@ pipeline { PYTHONPATH = "${env.WORKSPACE}/.venv/bin" AUTH_TOKEN = credentials('hf_token') CUDACXX = '/usr/local/cuda-12/bin/nvcc' - CMAKE_ARGS = "-DLLAMA_CUDA=on" + CMAKE_ARGS = "-DLLAMA_CUBLAS=on" } @@ -16,7 +16,7 @@ pipeline { stage('Checkout') { steps { -// cleanWs() + cleanWs() checkout scm } } @@ -106,14 +106,14 @@ pipeline { // sh 'rm -rf $JENKINS_HOME/ci_test_data/data/vectordb/test_client' -// cleanWs( -// cleanWhenNotBuilt: false, -// deleteDirs: true, -// disableDeferredWipeout: true, -// notFailBuild: true, -// patterns: [[pattern: '.gitignore', type: 'INCLUDE'], -// [pattern: '.propsfile', type: 'EXCLUDE']] -// ) + cleanWs( + cleanWhenNotBuilt: false, + deleteDirs: true, + disableDeferredWipeout: true, + notFailBuild: true, + patterns: [[pattern: '.gitignore', type: 'INCLUDE'], + [pattern: '.propsfile', type: 'EXCLUDE']] + ) } } } diff --git a/src/tests/components/llm_test.py b/src/tests/components/llm_test.py index 39fb420..d64e8da 100644 --- a/src/tests/components/llm_test.py +++ b/src/tests/components/llm_test.py @@ -7,11 +7,11 @@ config = get_config() llama_models = [ - "Llama-2-7b-chat", - "Llama-2-13b-chat", + # "Llama-2-7b-chat", + # "Llama-2-13b-chat", "gemma-7b-it", "Mixtral-8x7B-Instruct-v0.1", - "gemma-7b-it", + # "gemma-7b-it", ] hf_models = [ "meta-llama/Llama-2-7b-chat-hf", @@ -19,7 +19,9 @@ # 'mistralai/Mixtral-8x7B-Instruct-v0.1', "google/gemma-7b-it", ] -cpp_quantization = ["Q5_K_M", "Q5_K_M", "f16", "Q4_K_M", "f16"] +# cpp_quantization = ["Q5_K_M", "Q5_K_M", +cpp_quantization = ["f16", "Q4_K_M"] # , "f16"] +gpu_layers = ['-1', '-1', '16', '16'] hf_quantization = ["Q8", "Q4", "Q4"] # , 'Q4'] params = [(model, quant) for model, quant in zip(hf_models, hf_quantization)] @@ -33,12 +35,12 @@ def test_hf_web_pipe(hf_models, quantization): del model -params = [(model, quant) for model, quant in zip(llama_models, cpp_quantization)] +params = [(model, gpu_layer, quant) for model, gpu_layer, quant in zip(llama_models, gpu_layers, cpp_quantization)] -@pytest.mark.parametrize("model_name, quantization", params) -def test_llamacpp_pipe(model_name, quantization): - llm_ = LLM(quantization=quantization, model_name=model_name, pipeline="llama_cpp") +@pytest.mark.parametrize("model_name, gpu_layer, quantization", params) +def test_llamacpp_pipe(model_name, gpu_layer, quantization): + llm_ = LLM(quantization=quantization, model_name=model_name, n_gpu_layers=gpu_layer, pipeline="llama_cpp") model = llm_.load_model() response = model.invoke("Who are you?") assert isinstance(response, Text) From 2d06bcd0ddf9232d687fb2da6f63f34cb4d74b99 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 15:01:54 -0400 Subject: [PATCH 18/43] ,. --- src/grag/components/llm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/grag/components/llm.py b/src/grag/components/llm.py index 53cebef..e428f7a 100644 --- a/src/grag/components/llm.py +++ b/src/grag/components/llm.py @@ -120,13 +120,13 @@ def hf_pipeline(self, is_local=False): auth_token = os.getenv("AUTH_TOKEN") if not auth_token: raise ValueError("Authentication token not provided.") - tokenizer = AutoTokenizer.from_pretrained(hf_model, token=True) + tokenizer = AutoTokenizer.from_pretrained(hf_model, token=auth_token) model = AutoModelForCausalLM.from_pretrained( hf_model, quantization_config=quantization_config, device_map=self.device_map, torch_dtype=torch.float16, - token=True, + token=auth_token, ) pipe = pipeline( From 4b8420651ce51a4a3b09fd4ec3cb9546b0eb6b75 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 15:17:03 -0400 Subject: [PATCH 19/43] . --- ci/Jenkinsfile | 2 ++ ci/env_test.py | 3 +++ src/tests/components/llm_test.py | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 ci/env_test.py diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 8506a66..2e7f96a 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -24,6 +24,8 @@ pipeline { stage('Create venv'){ steps { sh 'python3 -m venv .venv' + sh 'python3 env_test.py' + sh 'exit 1' } } diff --git a/ci/env_test.py b/ci/env_test.py new file mode 100644 index 0000000..c01c6db --- /dev/null +++ b/ci/env_test.py @@ -0,0 +1,3 @@ +import os + +print(os.environ['AUTH_TOKEN']) diff --git a/src/tests/components/llm_test.py b/src/tests/components/llm_test.py index d64e8da..bdd832e 100644 --- a/src/tests/components/llm_test.py +++ b/src/tests/components/llm_test.py @@ -7,7 +7,7 @@ config = get_config() llama_models = [ - # "Llama-2-7b-chat", + "Llama-2-7b-chat", # "Llama-2-13b-chat", "gemma-7b-it", "Mixtral-8x7B-Instruct-v0.1", @@ -20,7 +20,7 @@ "google/gemma-7b-it", ] # cpp_quantization = ["Q5_K_M", "Q5_K_M", -cpp_quantization = ["f16", "Q4_K_M"] # , "f16"] +cpp_quantization = ["Q5_K_M", "f16", "Q4_K_M"] # , "f16"] gpu_layers = ['-1', '-1', '16', '16'] hf_quantization = ["Q8", "Q4", "Q4"] # , 'Q4'] params = [(model, quant) for model, quant in zip(hf_models, hf_quantization)] From ea0967b20510fdce739801fc4f3c0b774675f29f Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 15:17:47 -0400 Subject: [PATCH 20/43] . --- ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 2e7f96a..e166d0f 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -24,7 +24,7 @@ pipeline { stage('Create venv'){ steps { sh 'python3 -m venv .venv' - sh 'python3 env_test.py' + sh 'python3 ci/env_test.py' sh 'exit 1' } } From 2cbb47011b0adb66ad050e86784d9e8d28962636 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 15:19:07 -0400 Subject: [PATCH 21/43] . --- ci/Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index e166d0f..3669dd5 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -6,7 +6,8 @@ pipeline { } environment { PYTHONPATH = "${env.WORKSPACE}/.venv/bin" - AUTH_TOKEN = credentials('hf_token') +// AUTH_TOKEN = credentials('hf_token') + AUTH_TOKEN = 'ARJUN' CUDACXX = '/usr/local/cuda-12/bin/nvcc' CMAKE_ARGS = "-DLLAMA_CUBLAS=on" } From 6a58dc8aa754eb468a24b737d7e62a4c183b3cec Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 15:35:57 -0400 Subject: [PATCH 22/43] . --- ci/Jenkinsfile | 12 ++++++------ ci/modify_config.py | 2 +- src/grag/components/utils.py | 5 ++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 3669dd5..a1f1f62 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -7,7 +7,7 @@ pipeline { environment { PYTHONPATH = "${env.WORKSPACE}/.venv/bin" // AUTH_TOKEN = credentials('hf_token') - AUTH_TOKEN = 'ARJUN' +// AUTH_TOKEN = 'ARJUN' CUDACXX = '/usr/local/cuda-12/bin/nvcc' CMAKE_ARGS = "-DLLAMA_CUBLAS=on" } @@ -25,8 +25,6 @@ pipeline { stage('Create venv'){ steps { sh 'python3 -m venv .venv' - sh 'python3 ci/env_test.py' - sh 'exit 1' } } @@ -93,9 +91,11 @@ pipeline { sh 'docker pull chromadb/chroma' sh 'docker run -d --name jenkins-chroma -p 8000:8000 chromadb/chroma' withPythonEnv(PYTHONPATH){ - sh 'pip install pytest' - sh 'python3 ci/unlock_deeplake.py' - sh 'pytest src -vvv --junitxml=pytest-report.xml' + withCredentials([string(credentialsId: 'hf_token', variable: 'AUTH_TOKEN')]) { + sh 'pip install pytest' + sh 'python3 ci/unlock_deeplake.py' + sh 'pytest src -vvv --junitxml=pytest-report.xml' + } } } post { diff --git a/ci/modify_config.py b/ci/modify_config.py index f210f69..0eac61d 100644 --- a/ci/modify_config.py +++ b/ci/modify_config.py @@ -12,7 +12,7 @@ config['root']['root_path'] = f'{workspace}' config['data']['data_path'] = f'{jenkins_home}/ci_test_data/data' config['llm']['base_dir'] = f'{jenkins_home}/ci_test_models/models' -config['env']['env_path'] = f'{jenkins_home}/env_file/.env' +# config['env']['env_path'] = f'{jenkins_home}/env_file/.env' with open(f'{workspace}/src/config.ini', 'w') as configfile: config.write(configfile) diff --git a/src/grag/components/utils.py b/src/grag/components/utils.py index 509ecb3..072f9e7 100644 --- a/src/grag/components/utils.py +++ b/src/grag/components/utils.py @@ -73,5 +73,8 @@ def get_config() -> ConfigParser: config = ConfigParser(interpolation=ExtendedInterpolation()) config.read(config_path) print(f"Loaded config from {config_path}.") - load_dotenv(config['env']['env_path']) + # load_dotenv(config['env']['env_path']) + env_path = Path(config['env']['env_path']) + if env_path.exists(): + load_dotenv() return config From 08e4b7d47b7d5ade8891b3aafa55c9b67af5e67a Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 15:40:59 -0400 Subject: [PATCH 23/43] / --- ci/Jenkinsfile | 18 +++++++++--------- ci/modify_config.py | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index a1f1f62..61a7735 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -17,7 +17,7 @@ pipeline { stage('Checkout') { steps { - cleanWs() +// cleanWs() checkout scm } } @@ -109,14 +109,14 @@ pipeline { // sh 'rm -rf $JENKINS_HOME/ci_test_data/data/vectordb/test_client' - cleanWs( - cleanWhenNotBuilt: false, - deleteDirs: true, - disableDeferredWipeout: true, - notFailBuild: true, - patterns: [[pattern: '.gitignore', type: 'INCLUDE'], - [pattern: '.propsfile', type: 'EXCLUDE']] - ) +// cleanWs( +// cleanWhenNotBuilt: false, +// deleteDirs: true, +// disableDeferredWipeout: true, +// notFailBuild: true, +// patterns: [[pattern: '.gitignore', type: 'INCLUDE'], +// [pattern: '.propsfile', type: 'EXCLUDE']] +// ) } } } diff --git a/ci/modify_config.py b/ci/modify_config.py index 0eac61d..75ce45a 100644 --- a/ci/modify_config.py +++ b/ci/modify_config.py @@ -12,7 +12,7 @@ config['root']['root_path'] = f'{workspace}' config['data']['data_path'] = f'{jenkins_home}/ci_test_data/data' config['llm']['base_dir'] = f'{jenkins_home}/ci_test_models/models' -# config['env']['env_path'] = f'{jenkins_home}/env_file/.env' +config['env']['env_path'] = f'{jenkins_home}/ci_test_models/' with open(f'{workspace}/src/config.ini', 'w') as configfile: config.write(configfile) From 4c40ca930267187fd6b439fc55f81a1c389653b8 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 15:44:21 -0400 Subject: [PATCH 24/43] . --- src/grag/components/utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/grag/components/utils.py b/src/grag/components/utils.py index 072f9e7..cec1a06 100644 --- a/src/grag/components/utils.py +++ b/src/grag/components/utils.py @@ -51,7 +51,7 @@ def find_config_path(current_path: Path) -> Path: return current_path / config_path -def get_config() -> ConfigParser: +def get_config(load_env=False) -> ConfigParser: """Retrieves and parses the configuration settings from the 'config.ini' file. This function locates the 'config.ini' file by calling `find_config_path` using the script's current location. @@ -74,7 +74,8 @@ def get_config() -> ConfigParser: config.read(config_path) print(f"Loaded config from {config_path}.") # load_dotenv(config['env']['env_path']) - env_path = Path(config['env']['env_path']) - if env_path.exists(): - load_dotenv() + if load_env: + env_path = Path(config['env']['env_path']) + if env_path.exists(): + load_dotenv() return config From b91613446735bf054bdb851a3712f04af00cde51 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 15:51:40 -0400 Subject: [PATCH 25/43] . --- ci/Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 61a7735..5822e2e 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -32,7 +32,7 @@ pipeline { steps { withPythonEnv(PYTHONPATH){ sh 'pip install -e .' -// sh 'CMAKE_ARGS="-DLLAMA_CUDA=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir' + sh 'CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir' } } @@ -93,6 +93,7 @@ pipeline { withPythonEnv(PYTHONPATH){ withCredentials([string(credentialsId: 'hf_token', variable: 'AUTH_TOKEN')]) { sh 'pip install pytest' + sh 'python3 ci/env_test.py' sh 'python3 ci/unlock_deeplake.py' sh 'pytest src -vvv --junitxml=pytest-report.xml' } From 0ef41aef9d70aaa62e7f65da30caa6c7a7ea602d Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 17:00:27 -0400 Subject: [PATCH 26/43] token errors --- ci/Jenkinsfile | 27 ++++++++++++--------------- ci/env_test.py | 2 +- pyproject.toml | 3 ++- src/grag/components/llm.py | 9 ++++----- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 5822e2e..653ab5e 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -17,7 +17,7 @@ pipeline { stage('Checkout') { steps { -// cleanWs() + cleanWs() checkout scm } } @@ -31,8 +31,8 @@ pipeline { stage('Install dependencies'){ steps { withPythonEnv(PYTHONPATH){ - sh 'pip install -e .' - sh 'CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir' + sh 'pip install -e . --no-cache-dir' +// sh 'CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir' } } @@ -91,7 +91,7 @@ pipeline { sh 'docker pull chromadb/chroma' sh 'docker run -d --name jenkins-chroma -p 8000:8000 chromadb/chroma' withPythonEnv(PYTHONPATH){ - withCredentials([string(credentialsId: 'hf_token', variable: 'AUTH_TOKEN')]) { + withCredentials([string(credentialsId: 'hf_token', variable: 'HF_TOKEN')]) { sh 'pip install pytest' sh 'python3 ci/env_test.py' sh 'python3 ci/unlock_deeplake.py' @@ -106,18 +106,15 @@ pipeline { withChecks('Integration Tests'){ junit 'pytest-report.xml' } -// sh 'rm -rf $JENKINS_HOME/ci_test_data/data/vectordb/test_retriever' -// sh 'rm -rf $JENKINS_HOME/ci_test_data/data/vectordb/test_client' - -// cleanWs( -// cleanWhenNotBuilt: false, -// deleteDirs: true, -// disableDeferredWipeout: true, -// notFailBuild: true, -// patterns: [[pattern: '.gitignore', type: 'INCLUDE'], -// [pattern: '.propsfile', type: 'EXCLUDE']] -// ) + cleanWs( + cleanWhenNotBuilt: false, + deleteDirs: true, + disableDeferredWipeout: true, + notFailBuild: true, + patterns: [[pattern: '.gitignore', type: 'INCLUDE'], + [pattern: '.propsfile', type: 'EXCLUDE']] + ) } } } diff --git a/ci/env_test.py b/ci/env_test.py index c01c6db..c0eb597 100644 --- a/ci/env_test.py +++ b/ci/env_test.py @@ -1,3 +1,3 @@ import os -print(os.environ['AUTH_TOKEN']) +print(os.environ['HF_TOKEN']) diff --git a/pyproject.toml b/pyproject.toml index 9859013..765327b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,8 @@ dependencies = [ "huggingface_hub>=0.20.2", "pydantic>=2.5.0", "rouge-score>=0.1.2", - "deeplake>=3.8.27" + "deeplake>=3.8.27", + "bitsandbytes>=0.43", ] [project.urls] diff --git a/src/grag/components/llm.py b/src/grag/components/llm.py index e428f7a..bf0665d 100644 --- a/src/grag/components/llm.py +++ b/src/grag/components/llm.py @@ -17,7 +17,7 @@ from .utils import get_config -llm_conf = get_config()["llm"] +llm_conf = get_config(load_env=True)["llm"] print("CUDA: ", torch.cuda.is_available()) @@ -117,16 +117,15 @@ def hf_pipeline(self, is_local=False): except OSError: # LocalTokenNotFoundError: # If loading fails due to an auth token error, then load the token and retry # load_dotenv() - auth_token = os.getenv("AUTH_TOKEN") - if not auth_token: + if not os.getenv("HF_TOKEN"): raise ValueError("Authentication token not provided.") - tokenizer = AutoTokenizer.from_pretrained(hf_model, token=auth_token) + tokenizer = AutoTokenizer.from_pretrained(hf_model, token=True) model = AutoModelForCausalLM.from_pretrained( hf_model, quantization_config=quantization_config, device_map=self.device_map, torch_dtype=torch.float16, - token=auth_token, + token=True, ) pipe = pipeline( From 2fb66834cd09e9a7931c42aa09ea27de9486418d Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 17:02:57 -0400 Subject: [PATCH 27/43] . --- src/tests/components/llm_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tests/components/llm_test.py b/src/tests/components/llm_test.py index bdd832e..cc75810 100644 --- a/src/tests/components/llm_test.py +++ b/src/tests/components/llm_test.py @@ -8,7 +8,7 @@ llama_models = [ "Llama-2-7b-chat", - # "Llama-2-13b-chat", + "Llama-2-13b-chat", "gemma-7b-it", "Mixtral-8x7B-Instruct-v0.1", # "gemma-7b-it", @@ -19,8 +19,8 @@ # 'mistralai/Mixtral-8x7B-Instruct-v0.1', "google/gemma-7b-it", ] -# cpp_quantization = ["Q5_K_M", "Q5_K_M", -cpp_quantization = ["Q5_K_M", "f16", "Q4_K_M"] # , "f16"] +cpp_quantization = ["Q5_K_M", "Q5_K_M", "f16", "Q4_K_M"] +# cpp_quantization = ["Q5_K_M", "f16", "Q4_K_M"] # , "f16"] gpu_layers = ['-1', '-1', '16', '16'] hf_quantization = ["Q8", "Q4", "Q4"] # , 'Q4'] params = [(model, quant) for model, quant in zip(hf_models, hf_quantization)] From e2bdb31071bb9a9bc3c2459c1f4cd2234a5b9c00 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 17:30:06 -0400 Subject: [PATCH 28/43] CUDA issue, token issue --- ci/Jenkinsfile | 12 ++++++------ ci/env_test.py | 4 ++++ ci/modify_config.py | 2 +- src/grag/components/utils.py | 1 + src/grag/quantize/utils.py | 4 ++-- src/tests/components/llm_test.py | 2 +- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 653ab5e..b91247f 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -91,12 +91,12 @@ pipeline { sh 'docker pull chromadb/chroma' sh 'docker run -d --name jenkins-chroma -p 8000:8000 chromadb/chroma' withPythonEnv(PYTHONPATH){ - withCredentials([string(credentialsId: 'hf_token', variable: 'HF_TOKEN')]) { - sh 'pip install pytest' - sh 'python3 ci/env_test.py' - sh 'python3 ci/unlock_deeplake.py' - sh 'pytest src -vvv --junitxml=pytest-report.xml' - } +// withCredentials([string(credentialsId: 'hf_token', variable: 'HF_TOKEN')]) { + sh 'pip install pytest' + sh 'python3 ci/env_test.py' + sh 'python3 ci/unlock_deeplake.py' + sh 'pytest src -vvv --junitxml=pytest-report.xml' +// } } } post { diff --git a/ci/env_test.py b/ci/env_test.py index c0eb597..02b5df5 100644 --- a/ci/env_test.py +++ b/ci/env_test.py @@ -1,3 +1,7 @@ import os +from grag.components.utils import get_config + +get_config(load_env=True) + print(os.environ['HF_TOKEN']) diff --git a/ci/modify_config.py b/ci/modify_config.py index 75ce45a..f210f69 100644 --- a/ci/modify_config.py +++ b/ci/modify_config.py @@ -12,7 +12,7 @@ config['root']['root_path'] = f'{workspace}' config['data']['data_path'] = f'{jenkins_home}/ci_test_data/data' config['llm']['base_dir'] = f'{jenkins_home}/ci_test_models/models' -config['env']['env_path'] = f'{jenkins_home}/ci_test_models/' +config['env']['env_path'] = f'{jenkins_home}/env_file/.env' with open(f'{workspace}/src/config.ini', 'w') as configfile: config.write(configfile) diff --git a/src/grag/components/utils.py b/src/grag/components/utils.py index cec1a06..d2e3ffa 100644 --- a/src/grag/components/utils.py +++ b/src/grag/components/utils.py @@ -78,4 +78,5 @@ def get_config(load_env=False) -> ConfigParser: env_path = Path(config['env']['env_path']) if env_path.exists(): load_dotenv() + print(f"Loaded environment variables from {env_path}") return config diff --git a/src/grag/quantize/utils.py b/src/grag/quantize/utils.py index bc1d280..0b90516 100644 --- a/src/grag/quantize/utils.py +++ b/src/grag/quantize/utils.py @@ -51,7 +51,7 @@ def building_llamacpp(root_path: Union[str, Path]) -> None: os.chdir(f"{root_path}/llama.cpp/") try: subprocess.run(["which", "make"], check=True, stdout=subprocess.DEVNULL) - subprocess.run(["make", "LLAMA_CUBLAS=1"], check=True) + subprocess.run(["make", "LLAMA_CUDA=1"], check=True) print("Llama.cpp build successful.") except subprocess.CalledProcessError: try: @@ -64,7 +64,7 @@ def building_llamacpp(root_path: Union[str, Path]) -> None: "&&", "cmake", "..", - "-DLLAMA_CUBLAS=ON", + "-DLLAMA_CUDA=ON", "&&", "cmake", "--build", diff --git a/src/tests/components/llm_test.py b/src/tests/components/llm_test.py index cc75810..e339c82 100644 --- a/src/tests/components/llm_test.py +++ b/src/tests/components/llm_test.py @@ -21,7 +21,7 @@ ] cpp_quantization = ["Q5_K_M", "Q5_K_M", "f16", "Q4_K_M"] # cpp_quantization = ["Q5_K_M", "f16", "Q4_K_M"] # , "f16"] -gpu_layers = ['-1', '-1', '16', '16'] +gpu_layers = ['-1', '-1', '18', '18'] hf_quantization = ["Q8", "Q4", "Q4"] # , 'Q4'] params = [(model, quant) for model, quant in zip(hf_models, hf_quantization)] From 2292c4bc121b87f654e881c63f087257c7595da5 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 17:37:24 -0400 Subject: [PATCH 29/43] . --- ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index b91247f..bfad487 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -93,7 +93,7 @@ pipeline { withPythonEnv(PYTHONPATH){ // withCredentials([string(credentialsId: 'hf_token', variable: 'HF_TOKEN')]) { sh 'pip install pytest' - sh 'python3 ci/env_test.py' +// sh 'python3 ci/env_test.py' sh 'python3 ci/unlock_deeplake.py' sh 'pytest src -vvv --junitxml=pytest-report.xml' // } From 36026738d3a4d58a2fef0ed3dad813399c033618 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 17:47:47 -0400 Subject: [PATCH 30/43] . --- src/tests/components/llm_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/components/llm_test.py b/src/tests/components/llm_test.py index e339c82..4eac21a 100644 --- a/src/tests/components/llm_test.py +++ b/src/tests/components/llm_test.py @@ -4,7 +4,7 @@ from grag.components.llm import LLM from grag.components.utils import get_config -config = get_config() +config = get_config(load_env=True) llama_models = [ "Llama-2-7b-chat", From 81e7d9b77adf96dc8e87d3f0761d73cf3fa339c6 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 18:13:43 -0400 Subject: [PATCH 31/43] . --- ci/Jenkinsfile | 6 +++++- ci/modify_config.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index bfad487..53b2b01 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -10,6 +10,9 @@ pipeline { // AUTH_TOKEN = 'ARJUN' CUDACXX = '/usr/local/cuda-12/bin/nvcc' CMAKE_ARGS = "-DLLAMA_CUBLAS=on" + PATH="/usr/local/cuda-12.3/bin:$PATH" + LD_LIBRARY_PATH="/usr/local/cuda-12.3/lib64:$LD_LIBRARY_PATH" + PATH="/usr/local/cuda-12.3/bin${PATH:+:${PATH}}" } @@ -95,7 +98,8 @@ pipeline { sh 'pip install pytest' // sh 'python3 ci/env_test.py' sh 'python3 ci/unlock_deeplake.py' - sh 'pytest src -vvv --junitxml=pytest-report.xml' +// sh 'pytest src -vvv --junitxml=pytest-report.xml' + sh 'pytest src/tests/components/llm_test.py src/tests/quantize/quantize_test.py -vvv --junitxml=pytest-report.xml' // } } } diff --git a/ci/modify_config.py b/ci/modify_config.py index f210f69..0cc7ebc 100644 --- a/ci/modify_config.py +++ b/ci/modify_config.py @@ -12,7 +12,7 @@ config['root']['root_path'] = f'{workspace}' config['data']['data_path'] = f'{jenkins_home}/ci_test_data/data' config['llm']['base_dir'] = f'{jenkins_home}/ci_test_models/models' -config['env']['env_path'] = f'{jenkins_home}/env_file/.env' +config['env']['env_path'] = f'{jenkins_home}/env_file/' with open(f'{workspace}/src/config.ini', 'w') as configfile: config.write(configfile) From 4b211adafc3d9a5842890022b98f2f8894c68fbe Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 18:14:54 -0400 Subject: [PATCH 32/43] . --- ci/Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 53b2b01..b15faf3 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -12,7 +12,6 @@ pipeline { CMAKE_ARGS = "-DLLAMA_CUBLAS=on" PATH="/usr/local/cuda-12.3/bin:$PATH" LD_LIBRARY_PATH="/usr/local/cuda-12.3/lib64:$LD_LIBRARY_PATH" - PATH="/usr/local/cuda-12.3/bin${PATH:+:${PATH}}" } From aba300e28ebfde5e7f9c05178df1339e5a4e2e21 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 18:36:40 -0400 Subject: [PATCH 33/43] . --- ci/Jenkinsfile | 22 +++++++++++----------- src/tests/components/utils_test.py | 8 ++++++++ 2 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 src/tests/components/utils_test.py diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index b15faf3..75b63f9 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -19,7 +19,7 @@ pipeline { stage('Checkout') { steps { - cleanWs() +// cleanWs() checkout scm } } @@ -33,7 +33,7 @@ pipeline { stage('Install dependencies'){ steps { withPythonEnv(PYTHONPATH){ - sh 'pip install -e . --no-cache-dir' + sh 'pip install -e .' // sh 'CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir' } } @@ -98,7 +98,7 @@ pipeline { // sh 'python3 ci/env_test.py' sh 'python3 ci/unlock_deeplake.py' // sh 'pytest src -vvv --junitxml=pytest-report.xml' - sh 'pytest src/tests/components/llm_test.py src/tests/quantize/quantize_test.py -vvv --junitxml=pytest-report.xml' + sh 'pytest src/tests/components/utils_test.py -vvv --junitxml=pytest-report.xml' // } } } @@ -110,14 +110,14 @@ pipeline { junit 'pytest-report.xml' } - cleanWs( - cleanWhenNotBuilt: false, - deleteDirs: true, - disableDeferredWipeout: true, - notFailBuild: true, - patterns: [[pattern: '.gitignore', type: 'INCLUDE'], - [pattern: '.propsfile', type: 'EXCLUDE']] - ) +// cleanWs( +// cleanWhenNotBuilt: false, +// deleteDirs: true, +// disableDeferredWipeout: true, +// notFailBuild: true, +// patterns: [[pattern: '.gitignore', type: 'INCLUDE'], +// [pattern: '.propsfile', type: 'EXCLUDE']] +// ) } } } diff --git a/src/tests/components/utils_test.py b/src/tests/components/utils_test.py new file mode 100644 index 0000000..ddbca0f --- /dev/null +++ b/src/tests/components/utils_test.py @@ -0,0 +1,8 @@ +import os + +from grag.components.utils import get_config + + +def test_get_config(): + config = get_config(load_env=True) + assert os.environ["HF_TOKEN"] From e37ebff0033eb7e73c10cfec7f965a6474eb97fc Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 18:43:43 -0400 Subject: [PATCH 34/43] . --- ci/modify_config.py | 2 +- src/grag/components/utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/modify_config.py b/ci/modify_config.py index 0cc7ebc..f210f69 100644 --- a/ci/modify_config.py +++ b/ci/modify_config.py @@ -12,7 +12,7 @@ config['root']['root_path'] = f'{workspace}' config['data']['data_path'] = f'{jenkins_home}/ci_test_data/data' config['llm']['base_dir'] = f'{jenkins_home}/ci_test_models/models' -config['env']['env_path'] = f'{jenkins_home}/env_file/' +config['env']['env_path'] = f'{jenkins_home}/env_file/.env' with open(f'{workspace}/src/config.ini', 'w') as configfile: config.write(configfile) diff --git a/src/grag/components/utils.py b/src/grag/components/utils.py index d2e3ffa..958dc35 100644 --- a/src/grag/components/utils.py +++ b/src/grag/components/utils.py @@ -77,6 +77,6 @@ def get_config(load_env=False) -> ConfigParser: if load_env: env_path = Path(config['env']['env_path']) if env_path.exists(): - load_dotenv() + load_dotenv(env_path) print(f"Loaded environment variables from {env_path}") return config From 71c34a9672025bccf1684b33df77873d68267e44 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 18:45:04 -0400 Subject: [PATCH 35/43] . --- ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 75b63f9..e1e828f 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -98,7 +98,7 @@ pipeline { // sh 'python3 ci/env_test.py' sh 'python3 ci/unlock_deeplake.py' // sh 'pytest src -vvv --junitxml=pytest-report.xml' - sh 'pytest src/tests/components/utils_test.py -vvv --junitxml=pytest-report.xml' + sh 'pytest src/tests/components/llm_test.py -vvv --junitxml=pytest-report.xml' // } } } From 2b0db0b44916850902795fc2628fbcc7d50c3ec7 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 18:48:28 -0400 Subject: [PATCH 36/43] . --- src/tests/components/llm_test.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/tests/components/llm_test.py b/src/tests/components/llm_test.py index 4eac21a..c39dd72 100644 --- a/src/tests/components/llm_test.py +++ b/src/tests/components/llm_test.py @@ -34,14 +34,13 @@ def test_hf_web_pipe(hf_models, quantization): assert isinstance(response, Text) del model - -params = [(model, gpu_layer, quant) for model, gpu_layer, quant in zip(llama_models, gpu_layers, cpp_quantization)] - - -@pytest.mark.parametrize("model_name, gpu_layer, quantization", params) -def test_llamacpp_pipe(model_name, gpu_layer, quantization): - llm_ = LLM(quantization=quantization, model_name=model_name, n_gpu_layers=gpu_layer, pipeline="llama_cpp") - model = llm_.load_model() - response = model.invoke("Who are you?") - assert isinstance(response, Text) - del model +# params = [(model, gpu_layer, quant) for model, gpu_layer, quant in zip(llama_models, gpu_layers, cpp_quantization)] +# +# +# @pytest.mark.parametrize("model_name, gpu_layer, quantization", params) +# def test_llamacpp_pipe(model_name, gpu_layer, quantization): +# llm_ = LLM(quantization=quantization, model_name=model_name, n_gpu_layers=gpu_layer, pipeline="llama_cpp") +# model = llm_.load_model() +# response = model.invoke("Who are you?") +# assert isinstance(response, Text) +# del model From c543bd24f8e356cd3757bb6d5b609276cd32e146 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 18:51:08 -0400 Subject: [PATCH 37/43] . --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 765327b..8152278 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,8 @@ dependencies = [ "pydantic>=2.5.0", "rouge-score>=0.1.2", "deeplake>=3.8.27", - "bitsandbytes>=0.43", + "bitsandbytes>=0.43.0", + "accelerate>=0.28.0" ] [project.urls] From dba7428683297da2c2a9708f9373564e1a5a57c7 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 18:56:13 -0400 Subject: [PATCH 38/43] Final build --- ci/Jenkinsfile | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index e1e828f..d816f96 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -6,8 +6,6 @@ pipeline { } environment { PYTHONPATH = "${env.WORKSPACE}/.venv/bin" -// AUTH_TOKEN = credentials('hf_token') -// AUTH_TOKEN = 'ARJUN' CUDACXX = '/usr/local/cuda-12/bin/nvcc' CMAKE_ARGS = "-DLLAMA_CUBLAS=on" PATH="/usr/local/cuda-12.3/bin:$PATH" @@ -19,7 +17,7 @@ pipeline { stage('Checkout') { steps { -// cleanWs() + cleanWs() checkout scm } } @@ -34,7 +32,6 @@ pipeline { steps { withPythonEnv(PYTHONPATH){ sh 'pip install -e .' -// sh 'CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dir' } } @@ -93,13 +90,9 @@ pipeline { sh 'docker pull chromadb/chroma' sh 'docker run -d --name jenkins-chroma -p 8000:8000 chromadb/chroma' withPythonEnv(PYTHONPATH){ -// withCredentials([string(credentialsId: 'hf_token', variable: 'HF_TOKEN')]) { sh 'pip install pytest' -// sh 'python3 ci/env_test.py' sh 'python3 ci/unlock_deeplake.py' -// sh 'pytest src -vvv --junitxml=pytest-report.xml' - sh 'pytest src/tests/components/llm_test.py -vvv --junitxml=pytest-report.xml' -// } + sh 'pytest src -vvv --junitxml=pytest-report.xml' } } post { @@ -110,14 +103,14 @@ pipeline { junit 'pytest-report.xml' } -// cleanWs( -// cleanWhenNotBuilt: false, -// deleteDirs: true, -// disableDeferredWipeout: true, -// notFailBuild: true, -// patterns: [[pattern: '.gitignore', type: 'INCLUDE'], -// [pattern: '.propsfile', type: 'EXCLUDE']] -// ) + cleanWs( + cleanWhenNotBuilt: false, + deleteDirs: true, + disableDeferredWipeout: true, + notFailBuild: true, + patterns: [[pattern: '.gitignore', type: 'INCLUDE'], + [pattern: '.propsfile', type: 'EXCLUDE']] + ) } } } From 7324f5ee8cb997f34065eefb3f18e4f9449bec98 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 19:17:27 -0400 Subject: [PATCH 39/43] . --- src/tests/components/llm_test.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/tests/components/llm_test.py b/src/tests/components/llm_test.py index c39dd72..c29c1a5 100644 --- a/src/tests/components/llm_test.py +++ b/src/tests/components/llm_test.py @@ -11,18 +11,15 @@ "Llama-2-13b-chat", "gemma-7b-it", "Mixtral-8x7B-Instruct-v0.1", - # "gemma-7b-it", ] hf_models = [ "meta-llama/Llama-2-7b-chat-hf", "meta-llama/Llama-2-13b-chat-hf", - # 'mistralai/Mixtral-8x7B-Instruct-v0.1', "google/gemma-7b-it", ] cpp_quantization = ["Q5_K_M", "Q5_K_M", "f16", "Q4_K_M"] -# cpp_quantization = ["Q5_K_M", "f16", "Q4_K_M"] # , "f16"] gpu_layers = ['-1', '-1', '18', '18'] -hf_quantization = ["Q8", "Q4", "Q4"] # , 'Q4'] +hf_quantization = ["Q8", "Q4", "Q4"] params = [(model, quant) for model, quant in zip(hf_models, hf_quantization)] @@ -34,13 +31,14 @@ def test_hf_web_pipe(hf_models, quantization): assert isinstance(response, Text) del model -# params = [(model, gpu_layer, quant) for model, gpu_layer, quant in zip(llama_models, gpu_layers, cpp_quantization)] -# -# -# @pytest.mark.parametrize("model_name, gpu_layer, quantization", params) -# def test_llamacpp_pipe(model_name, gpu_layer, quantization): -# llm_ = LLM(quantization=quantization, model_name=model_name, n_gpu_layers=gpu_layer, pipeline="llama_cpp") -# model = llm_.load_model() -# response = model.invoke("Who are you?") -# assert isinstance(response, Text) -# del model + +params = [(model, gpu_layer, quant) for model, gpu_layer, quant in zip(llama_models, gpu_layers, cpp_quantization)] + + +@pytest.mark.parametrize("model_name, gpu_layer, quantization", params) +def test_llamacpp_pipe(model_name, gpu_layer, quantization): + llm_ = LLM(quantization=quantization, model_name=model_name, n_gpu_layers=gpu_layer, pipeline="llama_cpp") + model = llm_.load_model() + response = model.invoke("Who are you?") + assert isinstance(response, Text) + del model From b478ecbabd761ae4e6925c9e653738b19b80b890 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 20:11:11 -0400 Subject: [PATCH 40/43] FInal build --- src/config.ini | 4 ++-- src/tests/components/llm_test.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config.ini b/src/config.ini index 1f96419..18abdd9 100644 --- a/src/config.ini +++ b/src/config.ini @@ -9,8 +9,8 @@ max_new_tokens : 1024 temperature : 0.1 n_batch_gpu_cpp : 1024 n_ctx_cpp : 6000 -n_gpu_layers_cpp : 16 -# The number of layers to put on the GPU. Mixtral-18 +n_gpu_layers_cpp : -1 +# The number of layers to put on the GPU. Mixtral-18, gemma-20 std_out : True base_dir : ${root:root_path}/models diff --git a/src/tests/components/llm_test.py b/src/tests/components/llm_test.py index c29c1a5..66b51dd 100644 --- a/src/tests/components/llm_test.py +++ b/src/tests/components/llm_test.py @@ -18,7 +18,7 @@ "google/gemma-7b-it", ] cpp_quantization = ["Q5_K_M", "Q5_K_M", "f16", "Q4_K_M"] -gpu_layers = ['-1', '-1', '18', '18'] +gpu_layers = ['-1', '-1', '18', '16'] hf_quantization = ["Q8", "Q4", "Q4"] params = [(model, quant) for model, quant in zip(hf_models, hf_quantization)] From f17b032f99117a150a30c1dfc817dbb55664dbcf Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Wed, 3 Apr 2024 23:09:45 -0400 Subject: [PATCH 41/43] making sure to clear CUDA --- src/tests/components/multivec_retriever_test.py | 9 +-------- src/tests/components/vectordb/chroma_client_test.py | 5 +++++ .../components/vectordb/deeplake_client_test.py | 13 ------------- src/tests/rag/basic_rag_test.py | 6 ++++-- 4 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/tests/components/multivec_retriever_test.py b/src/tests/components/multivec_retriever_test.py index 2ac99c0..e057a86 100644 --- a/src/tests/components/multivec_retriever_test.py +++ b/src/tests/components/multivec_retriever_test.py @@ -7,14 +7,6 @@ from grag.components.vectordb.deeplake_client import DeepLakeClient from langchain_core.documents import Document -# res = subprocess.run(["echo", "$JENKINS_HOME"], check=True, capture_output=True) -# if res.stdout == "JENKINS_HOME": -# jenkins_home = os.getenv('JENKINS_HOME') -# test_path = Path(jenkins_home) / 'ci_test_data/data/vectordb/test_retriever' -# if os.path.exists(test_path): -# shutil.rmtree(test_path) -# print('Deleting test retriever: {}'.format(test_path)) -# else: config = get_config() test_path = Path(config['data']['data_path']) / 'vectordb/test_retriever' @@ -97,6 +89,7 @@ def test_retriever_add_docs(): assert len(retrieved) == len(ids) for ret, doc in zip(retrieved, docs): assert ret.metadata == doc.metadata + del client def test_retriever_aadd_docs(): diff --git a/src/tests/components/vectordb/chroma_client_test.py b/src/tests/components/vectordb/chroma_client_test.py index c491dfd..f07908c 100644 --- a/src/tests/components/vectordb/chroma_client_test.py +++ b/src/tests/components/vectordb/chroma_client_test.py @@ -9,6 +9,7 @@ def test_chroma_connection(): chroma_client = ChromaClient() response = chroma_client.test_connection() assert isinstance(response, int) + del chroma_client def test_chroma_add_docs(): @@ -52,6 +53,7 @@ def test_chroma_add_docs(): docs = [Document(page_content=doc) for doc in docs] chroma_client.add_docs(docs) assert len(chroma_client) == len(docs) + del chroma_client def test_chroma_aadd_docs(): @@ -96,6 +98,7 @@ def test_chroma_aadd_docs(): loop = asyncio.get_event_loop() loop.run_until_complete(chroma_client.aadd_docs(docs)) assert len(chroma_client) == len(docs) + del chroma_client chrome_get_chunk_params = [(1, False), (1, True), (2, False), (2, True)] @@ -122,6 +125,7 @@ def test_chroma_get_chunk(top_k, with_score): assert all(isinstance(doc[1], float) for doc in retrieved_chunks) else: assert all(isinstance(doc, Document) for doc in retrieved_chunks) + del chroma_client @pytest.mark.parametrize("top_k,with_score", chrome_get_chunk_params) @@ -146,3 +150,4 @@ def test_chroma_aget_chunk(top_k, with_score): assert all(isinstance(doc[1], float) for doc in retrieved_chunks) else: assert all(isinstance(doc, Document) for doc in retrieved_chunks) + del chroma_client diff --git a/src/tests/components/vectordb/deeplake_client_test.py b/src/tests/components/vectordb/deeplake_client_test.py index 7e0938d..70fcf31 100644 --- a/src/tests/components/vectordb/deeplake_client_test.py +++ b/src/tests/components/vectordb/deeplake_client_test.py @@ -8,19 +8,6 @@ from grag.components.vectordb.deeplake_client import DeepLakeClient from langchain_core.documents import Document -# res = subprocess.run(["echo", "$JENKINS_HOME"], check=True, capture_output=True) -# if res.stdout == "JENKINS_HOME": -# jenkins_home = os.getenv('JENKINS_HOME') -# test_path = Path(jenkins_home) / 'ci_test_data/data/vectordb/test_client' -# if os.path.exists(test_path): -# shutil.rmtree(test_path) -# print('Deleting test retriever: {}'.format(test_path)) -# else: -# test_path = dir_path = Path(__file__).parents[5] / 'data/vectordb/test_client' -# if os.path.exists(test_path): -# shutil.rmtree(test_path) -# print('Deleting test retriever: {}'.format(test_path)) - config = get_config() test_path = Path(config['data']['data_path']) / 'vectordb/test_client' if os.path.exists(test_path): diff --git a/src/tests/rag/basic_rag_test.py b/src/tests/rag/basic_rag_test.py index 0b93643..1695e93 100644 --- a/src/tests/rag/basic_rag_test.py +++ b/src/tests/rag/basic_rag_test.py @@ -9,7 +9,8 @@ def test_rag_stuff(): - rag = BasicRAG(doc_chain="stuff", retriever=retriever) + rag = BasicRAG(doc_chain="stuff", retriever=retriever, + llm_kwargs={"model_name": "Llama-2-7b-chat", "n_gpu_layers": "-1"}) response, sources = rag("What is Flash Attention?") assert isinstance(response, Text) assert isinstance(sources, List) @@ -18,7 +19,8 @@ def test_rag_stuff(): def test_rag_refine(): - rag = BasicRAG(doc_chain="refine", retriever=retriever) + rag = BasicRAG(doc_chain="refine", retriever=retriever, + llm_kwargs={"model_name": "Llama-2-7b-chat", "n_gpu_layers": "-1"}) response, sources = rag("What is Flash Attention?") assert isinstance(response, List) assert all(isinstance(s, str) for s in response) From 1fa9624ce9382b67beb8f742f761d319b54f9ab0 Mon Sep 17 00:00:00 2001 From: sanchitvj Date: Thu, 4 Apr 2024 13:52:36 -0400 Subject: [PATCH 42/43] deleting client --- src/tests/components/multivec_retriever_test.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/tests/components/multivec_retriever_test.py b/src/tests/components/multivec_retriever_test.py index e057a86..8211b3a 100644 --- a/src/tests/components/multivec_retriever_test.py +++ b/src/tests/components/multivec_retriever_test.py @@ -14,13 +14,15 @@ shutil.rmtree(test_path) print('Deleting test retriever: {}'.format(test_path)) -client = DeepLakeClient(collection_name="test_retriever") -retriever = Retriever(vectordb=client) # pass test collection +# client = DeepLakeClient(collection_name="test_retriever") +# retriever = Retriever(vectordb=client) # pass test collection doc = Document(page_content="Hello worlds", metadata={"source": "bars"}) def test_retriever_id_gen(): + client = DeepLakeClient(collection_name="test_retriever") + retriever = Retriever(vectordb=client) doc = Document(page_content="Hello world", metadata={"source": "bar"}) id_ = retriever.id_gen(doc) assert isinstance(id_, str) @@ -31,14 +33,18 @@ def test_retriever_id_gen(): doc.metadata["source"] = "bars" id_1 = retriever.id_gen(doc) assert id_ != id_1 + del client, retriever def test_retriever_gen_doc_ids(): + client = DeepLakeClient(collection_name="test_retriever") + retriever = Retriever(vectordb=client) docs = [Document(page_content="Hello world", metadata={"source": "bar"}), Document(page_content="Hello", metadata={"source": "foo"})] ids = retriever.gen_doc_ids(docs) assert len(ids) == len(docs) assert all(isinstance(id, str) for id in ids) + del client, retriever def test_retriever_split_docs(): @@ -46,6 +52,8 @@ def test_retriever_split_docs(): def test_retriever_add_docs(): + client = DeepLakeClient(collection_name="test_retriever") + retriever = Retriever(vectordb=client) # small enough docs to not split. docs = [Document(page_content= """And so on this rainbow day, with storms all around them, and blue sky @@ -89,7 +97,7 @@ def test_retriever_add_docs(): assert len(retrieved) == len(ids) for ret, doc in zip(retrieved, docs): assert ret.metadata == doc.metadata - del client + del client, retriever def test_retriever_aadd_docs(): From 2fe007a8ccf624b0fed68d06f05dda073a098b43 Mon Sep 17 00:00:00 2001 From: Arjun Bingly Date: Thu, 4 Apr 2024 16:29:06 -0400 Subject: [PATCH 43/43] Jenkins Pipeline --- ci/Jenkinsfile | 14 ++++---- ci/env_test.py | 7 ++++ ci/modify_config.py | 1 + ci/modify_config_test.py | 6 ---- pyproject.toml | 4 ++- src/config.ini | 7 ++-- src/grag/components/llm.py | 8 ++--- src/grag/components/multivec_retriever.py | 1 + src/grag/components/utils.py | 15 +++++--- src/grag/quantize/utils.py | 4 +-- src/tests/components/embedding_test.py | 1 + src/tests/components/llm_test.py | 19 +++++----- .../components/multivec_retriever_test.py | 36 ++++++++++++++----- src/tests/components/utils_test.py | 8 +++++ .../components/vectordb/chroma_client_test.py | 5 +++ .../vectordb/deeplake_client_test.py | 20 ++++++++--- src/tests/quantize/quantize_test.py | 3 ++ src/tests/rag/basic_rag_test.py | 6 ++-- 18 files changed, 115 insertions(+), 50 deletions(-) create mode 100644 ci/env_test.py delete mode 100644 ci/modify_config_test.py create mode 100644 src/tests/components/utils_test.py diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 56d3551..d816f96 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -6,6 +6,10 @@ pipeline { } environment { PYTHONPATH = "${env.WORKSPACE}/.venv/bin" + CUDACXX = '/usr/local/cuda-12/bin/nvcc' + CMAKE_ARGS = "-DLLAMA_CUBLAS=on" + PATH="/usr/local/cuda-12.3/bin:$PATH" + LD_LIBRARY_PATH="/usr/local/cuda-12.3/lib64:$LD_LIBRARY_PATH" } @@ -27,7 +31,7 @@ pipeline { stage('Install dependencies'){ steps { withPythonEnv(PYTHONPATH){ - sh "pip install -e ." + sh 'pip install -e .' } } @@ -35,7 +39,6 @@ pipeline { stage('Config'){ steps{ - sh 'echo $env.JENKINS_HOME' withPythonEnv(PYTHONPATH){ sh 'python3 ci/modify_config.py' sh 'rm -rf $JENKINS_HOME/ci_test_data/data/vectordb/ci_test' @@ -84,22 +87,21 @@ pipeline { stage('Tests'){ steps{ - sh 'echo $USER' sh 'docker pull chromadb/chroma' sh 'docker run -d --name jenkins-chroma -p 8000:8000 chromadb/chroma' withPythonEnv(PYTHONPATH){ sh 'pip install pytest' sh 'python3 ci/unlock_deeplake.py' - sh 'pytest src --junitxml=pytest-report.xml' + sh 'pytest src -vvv --junitxml=pytest-report.xml' } } post { always{ + sh 'docker stop jenkins-chroma' + sh 'docker rm jenkins-chroma' withChecks('Integration Tests'){ junit 'pytest-report.xml' } - sh 'docker stop jenkins-chroma' - sh 'docker rm jenkins-chroma' cleanWs( cleanWhenNotBuilt: false, diff --git a/ci/env_test.py b/ci/env_test.py new file mode 100644 index 0000000..02b5df5 --- /dev/null +++ b/ci/env_test.py @@ -0,0 +1,7 @@ +import os + +from grag.components.utils import get_config + +get_config(load_env=True) + +print(os.environ['HF_TOKEN']) diff --git a/ci/modify_config.py b/ci/modify_config.py index 759e88d..f210f69 100644 --- a/ci/modify_config.py +++ b/ci/modify_config.py @@ -12,6 +12,7 @@ config['root']['root_path'] = f'{workspace}' config['data']['data_path'] = f'{jenkins_home}/ci_test_data/data' config['llm']['base_dir'] = f'{jenkins_home}/ci_test_models/models' +config['env']['env_path'] = f'{jenkins_home}/env_file/.env' with open(f'{workspace}/src/config.ini', 'w') as configfile: config.write(configfile) diff --git a/ci/modify_config_test.py b/ci/modify_config_test.py deleted file mode 100644 index b93a40a..0000000 --- a/ci/modify_config_test.py +++ /dev/null @@ -1,6 +0,0 @@ -from grag.components.utils import get_config - -config = get_config() -print(f"{config['root']['root_path']=}") -print(f"{config['data']['data_path'] = }") -print(f"{config['llm']['base_dir'] = }") diff --git a/pyproject.toml b/pyproject.toml index 9859013..8152278 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,9 @@ dependencies = [ "huggingface_hub>=0.20.2", "pydantic>=2.5.0", "rouge-score>=0.1.2", - "deeplake>=3.8.27" + "deeplake>=3.8.27", + "bitsandbytes>=0.43.0", + "accelerate>=0.28.0" ] [project.urls] diff --git a/src/config.ini b/src/config.ini index 1760277..18abdd9 100644 --- a/src/config.ini +++ b/src/config.ini @@ -9,8 +9,8 @@ max_new_tokens : 1024 temperature : 0.1 n_batch_gpu_cpp : 1024 n_ctx_cpp : 6000 -n_gpu_layers_cpp : 16 -# The number of layers to put on the GPU. Mixtral-18 +n_gpu_layers_cpp : -1 +# The number of layers to put on the GPU. Mixtral-18, gemma-20 std_out : True base_dir : ${root:root_path}/models @@ -58,6 +58,9 @@ table_as_html : True [data] data_path : ${root:root_path}/data +[env] +env_path : ${root:root_path}/.env + [root] root_path : /home/ubuntu/volume_2k/Capstone_5 diff --git a/src/grag/components/llm.py b/src/grag/components/llm.py index 54f14e8..bf0665d 100644 --- a/src/grag/components/llm.py +++ b/src/grag/components/llm.py @@ -4,7 +4,6 @@ from pathlib import Path import torch -from dotenv import load_dotenv from langchain.callbacks.manager import CallbackManager from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler from langchain_community.llms import LlamaCpp @@ -18,7 +17,7 @@ from .utils import get_config -llm_conf = get_config()["llm"] +llm_conf = get_config(load_env=True)["llm"] print("CUDA: ", torch.cuda.is_available()) @@ -117,9 +116,8 @@ def hf_pipeline(self, is_local=False): ) except OSError: # LocalTokenNotFoundError: # If loading fails due to an auth token error, then load the token and retry - load_dotenv() - auth_token = os.getenv("AUTH_TOKEN") - if not auth_token: + # load_dotenv() + if not os.getenv("HF_TOKEN"): raise ValueError("Authentication token not provided.") tokenizer = AutoTokenizer.from_pretrained(hf_model, token=True) model = AutoModelForCausalLM.from_pretrained( diff --git a/src/grag/components/multivec_retriever.py b/src/grag/components/multivec_retriever.py index 41bff2d..dd9d240 100644 --- a/src/grag/components/multivec_retriever.py +++ b/src/grag/components/multivec_retriever.py @@ -78,6 +78,7 @@ def __init__( byte_store=self.store, # type: ignore id_key=self.id_key, ) + self.docstore = self.retriever.docstore self.splitter = TextSplitter() self.top_k: int = top_k self.retriever.search_kwargs = {"k": self.top_k} diff --git a/src/grag/components/utils.py b/src/grag/components/utils.py index 491c9ec..958dc35 100644 --- a/src/grag/components/utils.py +++ b/src/grag/components/utils.py @@ -12,6 +12,7 @@ from pathlib import Path from typing import List +from dotenv import load_dotenv from langchain_core.documents import Document @@ -42,7 +43,7 @@ def find_config_path(current_path: Path) -> Path: Raises: FileNotFoundError: If 'config.ini' cannot be found in any of the parent directories. """ - config_path = Path("src/config.ini") + config_path = Path("config.ini") while not (current_path / config_path).exists(): current_path = current_path.parent if current_path == current_path.parent: @@ -50,7 +51,7 @@ def find_config_path(current_path: Path) -> Path: return current_path / config_path -def get_config() -> ConfigParser: +def get_config(load_env=False) -> ConfigParser: """Retrieves and parses the configuration settings from the 'config.ini' file. This function locates the 'config.ini' file by calling `find_config_path` using the script's current location. @@ -67,9 +68,15 @@ def get_config() -> ConfigParser: else: config_path = find_config_path(script_location) os.environ["CONFIG_PATH"] = str(config_path) - print(f"Loaded config from {config_path}.") + # Initialize parser and read config config = ConfigParser(interpolation=ExtendedInterpolation()) config.read(config_path) - + print(f"Loaded config from {config_path}.") + # load_dotenv(config['env']['env_path']) + if load_env: + env_path = Path(config['env']['env_path']) + if env_path.exists(): + load_dotenv(env_path) + print(f"Loaded environment variables from {env_path}") return config diff --git a/src/grag/quantize/utils.py b/src/grag/quantize/utils.py index bc1d280..0b90516 100644 --- a/src/grag/quantize/utils.py +++ b/src/grag/quantize/utils.py @@ -51,7 +51,7 @@ def building_llamacpp(root_path: Union[str, Path]) -> None: os.chdir(f"{root_path}/llama.cpp/") try: subprocess.run(["which", "make"], check=True, stdout=subprocess.DEVNULL) - subprocess.run(["make", "LLAMA_CUBLAS=1"], check=True) + subprocess.run(["make", "LLAMA_CUDA=1"], check=True) print("Llama.cpp build successful.") except subprocess.CalledProcessError: try: @@ -64,7 +64,7 @@ def building_llamacpp(root_path: Union[str, Path]) -> None: "&&", "cmake", "..", - "-DLLAMA_CUBLAS=ON", + "-DLLAMA_CUDA=ON", "&&", "cmake", "--build", diff --git a/src/tests/components/embedding_test.py b/src/tests/components/embedding_test.py index 1eda90f..2aecc26 100644 --- a/src/tests/components/embedding_test.py +++ b/src/tests/components/embedding_test.py @@ -47,3 +47,4 @@ def test_embeddings(embedding_config): cosine_similarity(doc_vecs[0], doc_vecs[2]), ] assert similarity_scores[0] > similarity_scores[1] + del embedding diff --git a/src/tests/components/llm_test.py b/src/tests/components/llm_test.py index df0f4d9..66b51dd 100644 --- a/src/tests/components/llm_test.py +++ b/src/tests/components/llm_test.py @@ -2,21 +2,24 @@ import pytest from grag.components.llm import LLM +from grag.components.utils import get_config + +config = get_config(load_env=True) llama_models = [ "Llama-2-7b-chat", "Llama-2-13b-chat", - "Mixtral-8x7B-Instruct-v0.1", "gemma-7b-it", + "Mixtral-8x7B-Instruct-v0.1", ] hf_models = [ "meta-llama/Llama-2-7b-chat-hf", "meta-llama/Llama-2-13b-chat-hf", - # 'mistralai/Mixtral-8x7B-Instruct-v0.1', "google/gemma-7b-it", ] -cpp_quantization = ["Q5_K_M", "Q5_K_M", "Q4_K_M", "f16"] -hf_quantization = ["Q8", "Q4", "Q4"] # , 'Q4'] +cpp_quantization = ["Q5_K_M", "Q5_K_M", "f16", "Q4_K_M"] +gpu_layers = ['-1', '-1', '18', '16'] +hf_quantization = ["Q8", "Q4", "Q4"] params = [(model, quant) for model, quant in zip(hf_models, hf_quantization)] @@ -29,12 +32,12 @@ def test_hf_web_pipe(hf_models, quantization): del model -params = [(model, quant) for model, quant in zip(llama_models, cpp_quantization)] +params = [(model, gpu_layer, quant) for model, gpu_layer, quant in zip(llama_models, gpu_layers, cpp_quantization)] -@pytest.mark.parametrize("model_name, quantization", params) -def test_llamacpp_pipe(model_name, quantization): - llm_ = LLM(quantization=quantization, model_name=model_name, pipeline="llama_cpp") +@pytest.mark.parametrize("model_name, gpu_layer, quantization", params) +def test_llamacpp_pipe(model_name, gpu_layer, quantization): + llm_ = LLM(quantization=quantization, model_name=model_name, n_gpu_layers=gpu_layer, pipeline="llama_cpp") model = llm_.load_model() response = model.invoke("Who are you?") assert isinstance(response, Text) diff --git a/src/tests/components/multivec_retriever_test.py b/src/tests/components/multivec_retriever_test.py index 3f847bd..8211b3a 100644 --- a/src/tests/components/multivec_retriever_test.py +++ b/src/tests/components/multivec_retriever_test.py @@ -1,19 +1,31 @@ -import json +import os +import shutil +from pathlib import Path from grag.components.multivec_retriever import Retriever +from grag.components.utils import get_config from grag.components.vectordb.deeplake_client import DeepLakeClient from langchain_core.documents import Document -client = DeepLakeClient(collection_name="ci_test") -retriever = Retriever(vectordb=client) # pass test collection +config = get_config() + +test_path = Path(config['data']['data_path']) / 'vectordb/test_retriever' +if os.path.exists(test_path): + shutil.rmtree(test_path) + print('Deleting test retriever: {}'.format(test_path)) + +# client = DeepLakeClient(collection_name="test_retriever") +# retriever = Retriever(vectordb=client) # pass test collection doc = Document(page_content="Hello worlds", metadata={"source": "bars"}) -def test_retriver_id_gen(): +def test_retriever_id_gen(): + client = DeepLakeClient(collection_name="test_retriever") + retriever = Retriever(vectordb=client) doc = Document(page_content="Hello world", metadata={"source": "bar"}) id_ = retriever.id_gen(doc) - assert isinstance(id, str) + assert isinstance(id_, str) assert len(id_) == 32 doc.page_content = doc.page_content + 'ABC' id_1 = retriever.id_gen(doc) @@ -21,14 +33,18 @@ def test_retriver_id_gen(): doc.metadata["source"] = "bars" id_1 = retriever.id_gen(doc) assert id_ != id_1 + del client, retriever def test_retriever_gen_doc_ids(): + client = DeepLakeClient(collection_name="test_retriever") + retriever = Retriever(vectordb=client) docs = [Document(page_content="Hello world", metadata={"source": "bar"}), Document(page_content="Hello", metadata={"source": "foo"})] ids = retriever.gen_doc_ids(docs) assert len(ids) == len(docs) assert all(isinstance(id, str) for id in ids) + del client, retriever def test_retriever_split_docs(): @@ -36,6 +52,8 @@ def test_retriever_split_docs(): def test_retriever_add_docs(): + client = DeepLakeClient(collection_name="test_retriever") + retriever = Retriever(vectordb=client) # small enough docs to not split. docs = [Document(page_content= """And so on this rainbow day, with storms all around them, and blue sky @@ -75,11 +93,11 @@ def test_retriever_add_docs(): ] ids = retriever.gen_doc_ids(docs) retriever.add_docs(docs) - retrieved = retriever.store.mget(ids) + retrieved = retriever.docstore.mget(ids) assert len(retrieved) == len(ids) - for i, doc in enumerate(docs): - retrieved_doc = json.loads(retrieved[i].decode()) - assert doc.metadata == retrieved_doc.metadata + for ret, doc in zip(retrieved, docs): + assert ret.metadata == doc.metadata + del client, retriever def test_retriever_aadd_docs(): diff --git a/src/tests/components/utils_test.py b/src/tests/components/utils_test.py new file mode 100644 index 0000000..ddbca0f --- /dev/null +++ b/src/tests/components/utils_test.py @@ -0,0 +1,8 @@ +import os + +from grag.components.utils import get_config + + +def test_get_config(): + config = get_config(load_env=True) + assert os.environ["HF_TOKEN"] diff --git a/src/tests/components/vectordb/chroma_client_test.py b/src/tests/components/vectordb/chroma_client_test.py index c491dfd..f07908c 100644 --- a/src/tests/components/vectordb/chroma_client_test.py +++ b/src/tests/components/vectordb/chroma_client_test.py @@ -9,6 +9,7 @@ def test_chroma_connection(): chroma_client = ChromaClient() response = chroma_client.test_connection() assert isinstance(response, int) + del chroma_client def test_chroma_add_docs(): @@ -52,6 +53,7 @@ def test_chroma_add_docs(): docs = [Document(page_content=doc) for doc in docs] chroma_client.add_docs(docs) assert len(chroma_client) == len(docs) + del chroma_client def test_chroma_aadd_docs(): @@ -96,6 +98,7 @@ def test_chroma_aadd_docs(): loop = asyncio.get_event_loop() loop.run_until_complete(chroma_client.aadd_docs(docs)) assert len(chroma_client) == len(docs) + del chroma_client chrome_get_chunk_params = [(1, False), (1, True), (2, False), (2, True)] @@ -122,6 +125,7 @@ def test_chroma_get_chunk(top_k, with_score): assert all(isinstance(doc[1], float) for doc in retrieved_chunks) else: assert all(isinstance(doc, Document) for doc in retrieved_chunks) + del chroma_client @pytest.mark.parametrize("top_k,with_score", chrome_get_chunk_params) @@ -146,3 +150,4 @@ def test_chroma_aget_chunk(top_k, with_score): assert all(isinstance(doc[1], float) for doc in retrieved_chunks) else: assert all(isinstance(doc, Document) for doc in retrieved_chunks) + del chroma_client diff --git a/src/tests/components/vectordb/deeplake_client_test.py b/src/tests/components/vectordb/deeplake_client_test.py index cea5e61..70fcf31 100644 --- a/src/tests/components/vectordb/deeplake_client_test.py +++ b/src/tests/components/vectordb/deeplake_client_test.py @@ -1,9 +1,19 @@ import asyncio +import os +import shutil +from pathlib import Path import pytest +from grag.components.utils import get_config from grag.components.vectordb.deeplake_client import DeepLakeClient from langchain_core.documents import Document +config = get_config() +test_path = Path(config['data']['data_path']) / 'vectordb/test_client' +if os.path.exists(test_path): + shutil.rmtree(test_path) + print('Deleting test retriever: {}'.format(test_path)) + def test_deeplake_add_docs(): docs = [ @@ -40,7 +50,7 @@ def test_deeplake_add_docs(): storm-clouds was split to the blinding zigzag of lightning, and the thunder rolled and boomed, like the Colorado in flood.""", ] - deeplake_client = DeepLakeClient(collection_name="test") + deeplake_client = DeepLakeClient(collection_name="test_client") if len(deeplake_client) > 0: deeplake_client.delete() docs = [Document(page_content=doc) for doc in docs] @@ -49,7 +59,7 @@ def test_deeplake_add_docs(): del deeplake_client -def test_chroma_aadd_docs(): +def test_deeplake_aadd_docs(): docs = [ """And so on this rainbow day, with storms all around them, and blue sky above, they rode only as far as the valley. But from there, before they @@ -84,7 +94,7 @@ def test_chroma_aadd_docs(): storm-clouds was split to the blinding zigzag of lightning, and the thunder rolled and boomed, like the Colorado in flood.""", ] - deeplake_client = DeepLakeClient(collection_name="test") + deeplake_client = DeepLakeClient(collection_name="test_client") if len(deeplake_client) > 0: deeplake_client.delete() docs = [Document(page_content=doc) for doc in docs] @@ -108,7 +118,7 @@ def test_deeplake_get_chunk(top_k, with_score): ankles from Joel Creech's lasso had never mended. The girl was unutterably happy, but it was possible that she would never race a horse again.""" - deeplake_client = DeepLakeClient(collection_name="test", read_only=True) + deeplake_client = DeepLakeClient(collection_name="test_client", read_only=True) retrieved_chunks = deeplake_client.get_chunk( query=query, top_k=top_k, with_score=with_score ) @@ -132,7 +142,7 @@ def test_deeplake_aget_chunk(top_k, with_score): ankles from Joel Creech's lasso had never mended. The girl was unutterably happy, but it was possible that she would never race a horse again.""" - deeplake_client = DeepLakeClient(collection_name="test", read_only=True) + deeplake_client = DeepLakeClient(collection_name="test_client", read_only=True) loop = asyncio.get_event_loop() retrieved_chunks = loop.run_until_complete( deeplake_client.aget_chunk(query=query, top_k=top_k, with_score=with_score) diff --git a/src/tests/quantize/quantize_test.py b/src/tests/quantize/quantize_test.py index af0e9dd..68078fe 100644 --- a/src/tests/quantize/quantize_test.py +++ b/src/tests/quantize/quantize_test.py @@ -1,4 +1,5 @@ import os +import shutil from pathlib import Path from grag.quantize.utils import ( @@ -9,6 +10,8 @@ ) root_path = Path(__file__).parent / "test_data" +if os.path.exists(root_path): + shutil.rmtree(root_path) os.makedirs(root_path, exist_ok=True) diff --git a/src/tests/rag/basic_rag_test.py b/src/tests/rag/basic_rag_test.py index 0b93643..1695e93 100644 --- a/src/tests/rag/basic_rag_test.py +++ b/src/tests/rag/basic_rag_test.py @@ -9,7 +9,8 @@ def test_rag_stuff(): - rag = BasicRAG(doc_chain="stuff", retriever=retriever) + rag = BasicRAG(doc_chain="stuff", retriever=retriever, + llm_kwargs={"model_name": "Llama-2-7b-chat", "n_gpu_layers": "-1"}) response, sources = rag("What is Flash Attention?") assert isinstance(response, Text) assert isinstance(sources, List) @@ -18,7 +19,8 @@ def test_rag_stuff(): def test_rag_refine(): - rag = BasicRAG(doc_chain="refine", retriever=retriever) + rag = BasicRAG(doc_chain="refine", retriever=retriever, + llm_kwargs={"model_name": "Llama-2-7b-chat", "n_gpu_layers": "-1"}) response, sources = rag("What is Flash Attention?") assert isinstance(response, List) assert all(isinstance(s, str) for s in response)