Skip to content

Commit

Permalink
[Dev] Init dev docker
Browse files Browse the repository at this point in the history
  • Loading branch information
lshmouse committed Sep 20, 2024
1 parent bcf96d6 commit 7ab48ba
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ bazel test --config=cpplint //experimental/cpp_example/...
- See: https://github.com/kriscfoster/multi-language-bazel-monorepo
- https://github.com/yechuan51/multi-language-bazel-monorepo
- See: https://github.com/aspect-build/bazel-examples/tree/main
- Linter: https://pigweed.dev/automated_analysis.html
- Linter: https://pigweed.dev/automated_analysis.html
3 changes: 3 additions & 0 deletions dev/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
TAG=latest
docker build docker -f docker/dev.x86_64.dockerfile -t ai-playground:$TAG
17 changes: 17 additions & 0 deletions dev/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## ML Dev Docker

### Build
```
docker build . -f ml.dockerfiles -t registry.qcraftai.com/global/ml-dev-docker
```

### Run
```
docker run --runtime=nvidia -it registry.qcraftai.com/global/ml-dev-docker
```

```
nvcc -V
```

### References
8 changes: 8 additions & 0 deletions dev/docker/dev.x86_64.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM nvidia/cuda:12.2.2-cudnn8-devel-ubuntu22.04
LABEL maintainer="[email protected]"

COPY installers/ /tmp/installers/

RUN bash /tmp/installers/install_minimal_environment.sh
RUN bash /tmp/installers/install_developer_tools.sh
RUN bash /tmp/installers/install_training_support.sh
6 changes: 6 additions & 0 deletions dev/docker/installers/install_developer_tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# TODO: Install protoc compiler
# TODO: Install kubectl
# TODO: Install argo
# TODO: Install helm
20 changes: 20 additions & 0 deletions dev/docker/installers/install_minimal_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

apt-get -y update \
&& apt-get install -y software-properties-common \
&& add-apt-repository ppa:deadsnakes/ppa

apt install -y bash \
build-essential \
git \
git-lfs \
curl \
ca-certificates \
libsndfile1-dev \
libgl1 \
python3.10 \
python3-pip \
python3.10-venv && \
rm -rf /var/lib/apt/lists

# TODO: Install bazel
3 changes: 3 additions & 0 deletions dev/docker/installers/install_training_support.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

pip install --upgrade numpy torch accelerate triton torchvision transformers huggingface_hub
74 changes: 74 additions & 0 deletions playground.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash
set -u

TOP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
source $TOP_DIR/scripts/playground.bashrc

function _usage() {
echo -e "\n${RED}Usage${NO_COLOR}:
.${BOLD}/playground.sh${NO_COLOR} [OPTION]"
echo -e "\n${RED}Options${NO_COLOR}:
${BLUE}start_dev_docker [options]${NO_COLOR}: start a development docker container.
${BLUE}stop_dev_docker [options]${NO_COLOR}: stop the development docker container.
${BLUE}usage${NO_COLOR}: show this message and exit
"
}

function start_dev_docker() {
local image_name="ai-playground-dev:latest"
local container_name="ai-playground-dev"
local mount_dir="${TOP_DIR}"
local mount_point="/ai-playground"

if [ -z "$(docker ps -q -f name=$container_name)" ]; then
echo "Starting dev docker container..."
docker run -it --rm \
-v $mount_dir:$mount_point \
-w $mount_point \
--name $container_name \
$image_name \
/bin/bash
else
echo "Dev docker container is already running. Just attaching to it..."
docker exec -it $container_name /bin/bash
fi
}

function stop_dev_docker() {
local container_name="ai-playground-dev"

if [ -z "$(docker ps -q -f name=$container_name)" ]; then
echo "Dev docker container is not running. Exiting..."
exit 1
else
echo "Stopping dev docker container..."
docker stop $container_name
fi
}

function main() {
if [ "$#" -eq 0 ]; then
_usage
exit 0
fi

local cmd="$1"
shift

case "$cmd" in
start_dev_docker)
start_dev_docker "$@"
;;
stop_dev_docker)
stop_dev_docker "$@"
;;
usage)
_usage
;;
-h | --help)
_usage
;;
esac
}

main "$@"
Empty file added scripts/common.bashrc
Empty file.
56 changes: 56 additions & 0 deletions scripts/playground.bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

TOP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"

: ${VERBOSE:=yes}

BOLD='\033[1m'
RED='\033[0;31m'
BLUE='\033[1;34;48m'
GREEN='\033[32m'
WHITE='\033[34m'
YELLOW='\033[33m'
NO_COLOR='\033[0m'

function info() {
(echo >&2 -e "[${WHITE}${BOLD}INFO${NO_COLOR}] $*")
}

function error() {
(echo >&2 -e "[${RED}ERROR${NO_COLOR}] $*")
}

function warning() {
(echo >&2 -e "${YELLOW}[WARNING] $*${NO_COLOR}")
}

function ok() {
(echo >&2 -e "[${GREEN}${BOLD} OK ${NO_COLOR}] $*")
}

function print_delim() {
echo "=============================================="
}

function get_now() {
date +%s
}

function time_elapsed_s() {
local start="${1:-$(get_now)}"
local end="$(get_now)"
echo "$end - $start" | bc -l
}

function success() {
print_delim
ok "$1"
print_delim
}

function fail() {
print_delim
error "$1"
print_delim
exit 1
}
2 changes: 2 additions & 0 deletions scripts/start_dev_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash

0 comments on commit 7ab48ba

Please sign in to comment.