Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion instill/helpers/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@

import instill
from instill.helpers.const import DEFAULT_DEPENDENCIES
from instill.utils.logger import Logger

if __name__ == "__main__":
Logger.i("[Instill Builder] Setup docker...")
client = docker.from_env()
shutil.copyfile(
__file__.replace("build.py", "Dockerfile"), os.getcwd() + "/Dockerfile"
)

try:
Logger.i("[Instill Builder] Loading config file...")
with open("instill.yaml", "r", encoding="utf8") as f:
Logger.i("[Instill Builder] Parsing config file...")
config = yaml.safe_load(f)

build = config["build"]
Expand All @@ -37,6 +41,7 @@
packages_str += p + " "
packages_str += f"instill-sdk=={instill_version}"

Logger.i("[Instill Builder] Building model image...")
img, _ = client.images.build(
path="./",
rm=True,
Expand All @@ -50,8 +55,11 @@
quiet=False,
)
img.tag(f"{registry}/{repo}", tag)
Logger.i("[Instill Builder] Pushing model image...")
client.images.push(f"{registry}/{repo}", tag=tag)
except Exception as e:
print(e)
Logger.e("[Instill Builder] Build failed")
Logger.e(e)
finally:
os.remove("Dockerfile")
Logger.i("[Instill Builder] Build successful")
32 changes: 23 additions & 9 deletions instill/helpers/ray_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,34 @@ def __init__(
self.use_gpu = use_gpu
# params
if use_gpu:
self._update_num_cpus(0.25)
self._update_num_gpus(0.2)
self.update_num_cpus(0.25)
self.update_num_gpus(0.2)
else:
self._update_num_cpus(0.25)
self.update_num_cpus(0.25)

def _update_num_cpus(self, num_cpus: float):
def update_num_cpus(self, num_cpus: float):
if self._deployment.ray_actor_options is not None:
self._deployment.ray_actor_options.update({"num_cpus": num_cpus})

def _update_memory(self, memory: float):
return self

def update_memory(self, memory: float):
if self._deployment.ray_actor_options is not None:
self._deployment.ray_actor_options.update({"memory": memory})

def _update_num_gpus(self, num_gpus: float):
return self

def update_num_gpus(self, num_gpus: float):
if self._deployment.ray_actor_options is not None:
self._deployment.ray_actor_options.update({"num_gpus": num_gpus})

return self

def _determine_vram_usage(self, model_path: str, total_vram: str):
warn(
"determine vram usage base on file size will soon be removed",
PendingDeprecationWarning,
)
if total_vram == "":
return 0.25
if os.path.isfile(model_path):
Expand All @@ -75,6 +85,10 @@ def _determine_vram_usage(self, model_path: str, total_vram: str):
raise ModelPathException

def _determine_ram_usage(self, model_path: str):
warn(
"determine ram usage base on file size will soon be removed",
PendingDeprecationWarning,
)
if os.path.isfile(model_path):
return max(
RAM_MINIMUM_RESERVE * (1024 * 1024 * 1024),
Expand Down Expand Up @@ -124,13 +138,13 @@ def deploy(self, model_folder_path: str, ray_addr: str, total_vram: str):

if self.use_gpu:
if model_name in MODEL_VRAM_OVERRIDE_LIST:
self._update_num_gpus(MODEL_VRAM_OVERRIDE_LIST[model_name])
self.update_num_gpus(MODEL_VRAM_OVERRIDE_LIST[model_name])
else:
self._update_num_gpus(
self.update_num_gpus(
self._determine_vram_usage(model_folder_path, total_vram)
)
else:
self._update_memory(self._determine_ram_usage(model_folder_path))
self.update_memory(self._determine_ram_usage(model_folder_path))

if model_name in MODEL_VRAM_OVERRIDE_LIST:
self.update_min_replicas(1)
Expand Down