Skip to content

Commit afe98f7

Browse files
committed
Merge branch 'dev-guide' of https://github.com/Rajrahane/remote-vector-index-builder into dev-guide
Signed-off-by: Rajvaibhav Rahane <[email protected]>
2 parents 3207c56 + 74f1420 commit afe98f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2677
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Build and Publish Remote-Vector-Index-Builder API Image to Docker
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'remote_vector_index_builder/app/**'
9+
- '.github/workflows/publish_remote_api_image.yml'
10+
11+
permissions:
12+
id-token: write
13+
contents: read
14+
15+
jobs:
16+
build-and-publish-api-image:
17+
name: Build and Publish Remote-Vector-Index-Builder API Image
18+
if: github.repository == 'opensearch-project/remote-vector-index-builder'
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Build Docker Image
26+
run : |
27+
docker build -f ./remote_vector_index_builder/app/Dockerfile . -t opensearchstaging/remote-vector-index-builder:api-1.0.0
28+
docker tag opensearchstaging/remote-vector-index-builder:api-1.0.0 opensearchstaging/remote-vector-index-builder:api-latest
29+
30+
- name: Configure AWS Credentials
31+
uses: aws-actions/configure-aws-credentials@v4
32+
with:
33+
role-to-assume: ${{ secrets.REMOTE_VECTOR_DOCKER_ROLE }}
34+
aws-region: us-east-1
35+
36+
- name: Retrieve Values
37+
id: retrieve-values
38+
run: |
39+
DOCKERHUB_PASSWORD=`aws secretsmanager get-secret-value --secret-id jenkins-staging-dockerhub-credential --query SecretString --output text`
40+
echo "::add-mask::$DOCKERHUB_PASSWORD"
41+
echo "dockerhub-password=$DOCKERHUB_PASSWORD" >> $GITHUB_OUTPUT
42+
43+
- name: Login to DockerHub
44+
uses: docker/login-action@v3
45+
with:
46+
username: ${{ secrets.REMOTE_VECTOR_DOCKER_USERNAME }}
47+
password: ${{ steps.retrieve-values.outputs.dockerhub-password }}
48+
49+
- name: Push Docker Image
50+
run : |
51+
docker push opensearchstaging/remote-vector-index-builder:api-1.0.0
52+
docker push opensearchstaging/remote-vector-index-builder:api-latest
53+
- name: Runner Cleanups
54+
if: always()
55+
run: |
56+
docker logout

.github/workflows/run-tests.yml

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
run: |
3939
python -m pip install --upgrade pip
4040
python -m pip install -r remote_vector_index_builder/core/requirements.txt
41+
python -m pip install -r remote_vector_index_builder/app/requirements.txt
4142
python -m pip install -r test_remote_vector_index_builder/requirements.txt
4243
4344
- name: Run Linting - flake8

DEVELOPER_GUIDE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ docker build -f ./remote_vector_index_builder/core/Dockerfile . -t opensearchst
106106

107107
## Provisioning an instance for development
108108

109-
A NVIDIA GPU powered machine with CUDA Toolkit installed is required to build a Faiss base Image, and to run the Docker images to build an index.
109+
A NVIDIA GPU powered machine with CUDA Toolkit installed is required to build a Faiss base Image and to run the Docker images to build an index.
110110

111111
Typically an [EC2 G5](https://aws.amazon.com/ec2/instance-types/g5/) 2xlarge instance running a Deep Learning OSS Nvidia Driver AMI, with Docker CLI installed is recommended for development use.
112112

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright OpenSearch Contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# The OpenSearch Contributors require contributions made to
5+
# this file be licensed under the Apache-2.0 license or a
6+
# compatible open source license.
7+
8+
FROM opensearchstaging/remote-vector-index-builder:core-latest
9+
10+
WORKDIR /remote_vector_index_builder
11+
12+
COPY ./remote_vector_index_builder/app/requirements.txt /remote_vector_index_builder/app/requirements.txt
13+
14+
RUN pip install --no-cache-dir --upgrade -r /remote_vector_index_builder/app/requirements.txt
15+
16+
COPY ./remote_vector_index_builder/app /remote_vector_index_builder/app
17+
18+
ENV PYTHONPATH='${PYTHONPATH}:/tmp/faiss/build/faiss/python:/remote_vector_index_builder'
19+
20+
RUN ["python", "app/test_imports.py"]
21+
22+
CMD ["fastapi", "run", "app/main.py", "--port", "1025"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright OpenSearch Contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# The OpenSearch Contributors require contributions made to
5+
# this file be licensed under the Apache-2.0 license or a
6+
# compatible open source license.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright OpenSearch Contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# The OpenSearch Contributors require contributions made to
5+
# this file be licensed under the Apache-2.0 license or a
6+
# compatible open source license.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright OpenSearch Contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# The OpenSearch Contributors require contributions made to
5+
# this file be licensed under the Apache-2.0 license or a
6+
# compatible open source license.
7+
8+
from pydantic_settings import BaseSettings
9+
from app.storage.types import RequestStoreType
10+
from typing import Optional
11+
12+
13+
class Settings(BaseSettings):
14+
"""
15+
Settings class for the application. Pulls the settings
16+
from the Docker container environment variables
17+
"""
18+
19+
# Request Store settings
20+
request_store_type: RequestStoreType = RequestStoreType.MEMORY
21+
22+
# In memory settings
23+
request_store_max_size: int = 1000000
24+
request_store_ttl_seconds: Optional[int] = 600
25+
26+
# Resource Manager settings, in bytes
27+
gpu_memory_limit: float = 24.0 * 10**9
28+
cpu_memory_limit: float = 32.0 * 10**9
29+
30+
# Workflow Executor settings
31+
max_workers: int = 5
32+
33+
# Service settings
34+
service_name: str = "remote-vector-index-builder-api"
35+
log_level: str = "INFO"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright OpenSearch Contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# The OpenSearch Contributors require contributions made to
5+
# this file be licensed under the Apache-2.0 license or a
6+
# compatible open source license.
7+
class ApiError(Exception):
8+
"""Base exception for api errors"""
9+
10+
pass
11+
12+
13+
class HashCollisionError(ApiError):
14+
"""Raised when there's a hash collision in the Request Store"""
15+
16+
pass
17+
18+
19+
class CapacityError(ApiError):
20+
"""Raised when the worker does not have enough capacity to fulfill the request"""
21+
22+
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Copyright OpenSearch Contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# The OpenSearch Contributors require contributions made to
5+
# this file be licensed under the Apache-2.0 license or a
6+
# compatible open source license.
7+
8+
import threading
9+
10+
11+
class ResourceManager:
12+
"""
13+
A thread-safe resource manager that tracks and manages GPU and CPU memory allocations.
14+
15+
This class provides mechanisms to safely allocate and release memory resources
16+
in a multi-threaded environment, ensuring that memory usage doesn't exceed
17+
the specified limits.
18+
19+
Attributes:
20+
_total_gpu_memory (float): Total available GPU memory in bytes
21+
_total_cpu_memory (float): Total available CPU memory in bytes
22+
_available_gpu_memory (float): Currently available GPU memory in bytes
23+
_available_cpu_memory (float): Currently available CPU memory in bytes
24+
_lock (threading.Lock): Thread lock for synchronization
25+
"""
26+
27+
def __init__(self, total_gpu_memory: float, total_cpu_memory: float):
28+
"""
29+
Initialize the ResourceManager with specified GPU and CPU memory limits.
30+
31+
Args:
32+
total_gpu_memory (float): Total GPU memory available for allocation, in bytes
33+
total_cpu_memory (float): Total CPU memory available for allocation, in bytes
34+
"""
35+
self._total_gpu_memory = total_gpu_memory
36+
self._total_cpu_memory = total_cpu_memory
37+
self._available_gpu_memory = total_gpu_memory
38+
self._available_cpu_memory = total_cpu_memory
39+
self._lock = threading.Lock()
40+
41+
def allocate(self, gpu_memory: float, cpu_memory: float) -> bool:
42+
"""
43+
Attempt to allocate the specified amount of GPU and CPU memory.
44+
45+
Args:
46+
gpu_memory (float): Amount of GPU memory to allocate, in bytes
47+
cpu_memory (float): Amount of CPU memory to allocate, in bytes
48+
49+
Returns:
50+
bool: True if allocation was successful, False if insufficient resources
51+
"""
52+
with self._lock:
53+
if not (
54+
self._available_gpu_memory >= gpu_memory
55+
and self._available_cpu_memory >= cpu_memory
56+
):
57+
return False
58+
self._available_gpu_memory -= gpu_memory
59+
self._available_cpu_memory -= cpu_memory
60+
return True
61+
62+
def release(self, gpu_memory: float, cpu_memory: float) -> None:
63+
"""
64+
Release previously allocated GPU and CPU memory back to the pool.
65+
66+
Args:
67+
gpu_memory (float): Amount of GPU memory to release, in bytes
68+
cpu_memory (float): Amount of CPU memory to release, in bytes
69+
"""
70+
with self._lock:
71+
self._available_gpu_memory += gpu_memory
72+
self._available_cpu_memory += cpu_memory
73+
74+
def get_available_gpu_memory(self) -> float:
75+
"""
76+
Get the current amount of available GPU memory.
77+
78+
Returns:
79+
float: Amount of available GPU memory in bytes
80+
"""
81+
with self._lock:
82+
return self._available_gpu_memory
83+
84+
def get_available_cpu_memory(self) -> float:
85+
"""
86+
Get the current amount of available GPU memory.
87+
88+
Returns:
89+
float: Amount of available GPU memory in bytes
90+
"""
91+
with self._lock:
92+
return self._available_cpu_memory
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright OpenSearch Contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# The OpenSearch Contributors require contributions made to
5+
# this file be licensed under the Apache-2.0 license or a
6+
# compatible open source license.

0 commit comments

Comments
 (0)