From 5cca64c840bbe4eb57d50ea052276c1122c898aa Mon Sep 17 00:00:00 2001 From: Shaohui Liu Date: Sat, 14 Sep 2024 22:04:48 +0800 Subject: [PATCH] [Dev] Init dev docker --- README.md | 2 +- dev/build.sh | 3 + dev/docker/README.md | 17 +++++ dev/docker/dev.x86_64.dockerfile | 8 ++ .../installers/install_developer_tools.sh | 1 + .../installers/install_minimal_environment.sh | 20 +++++ .../installers/install_training_support.sh | 3 + playground.sh | 74 +++++++++++++++++++ scripts/common.bashrc | 0 scripts/playground.bashrc | 56 ++++++++++++++ scripts/start_dev_docker.sh | 2 + 11 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 dev/build.sh create mode 100644 dev/docker/README.md create mode 100644 dev/docker/dev.x86_64.dockerfile create mode 100644 dev/docker/installers/install_developer_tools.sh create mode 100644 dev/docker/installers/install_minimal_environment.sh create mode 100644 dev/docker/installers/install_training_support.sh create mode 100755 playground.sh create mode 100644 scripts/common.bashrc create mode 100644 scripts/playground.bashrc create mode 100755 scripts/start_dev_docker.sh diff --git a/README.md b/README.md index 3febfa1..44526f6 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file +- Linter: https://pigweed.dev/automated_analysis.html diff --git a/dev/build.sh b/dev/build.sh new file mode 100644 index 0000000..72919d6 --- /dev/null +++ b/dev/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash +TAG=latest +docker build docker -f docker/dev.x86_64.dockerfile -t ai-playground:$TAG diff --git a/dev/docker/README.md b/dev/docker/README.md new file mode 100644 index 0000000..af2112c --- /dev/null +++ b/dev/docker/README.md @@ -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 diff --git a/dev/docker/dev.x86_64.dockerfile b/dev/docker/dev.x86_64.dockerfile new file mode 100644 index 0000000..d78bdf6 --- /dev/null +++ b/dev/docker/dev.x86_64.dockerfile @@ -0,0 +1,8 @@ +FROM nvidia/cuda:12.2.2-cudnn8-devel-ubuntu22.04 +LABEL maintainer="Shaohui@qcraft.ai" + +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 diff --git a/dev/docker/installers/install_developer_tools.sh b/dev/docker/installers/install_developer_tools.sh new file mode 100644 index 0000000..a9bf588 --- /dev/null +++ b/dev/docker/installers/install_developer_tools.sh @@ -0,0 +1 @@ +#!/bin/bash diff --git a/dev/docker/installers/install_minimal_environment.sh b/dev/docker/installers/install_minimal_environment.sh new file mode 100644 index 0000000..50d5d42 --- /dev/null +++ b/dev/docker/installers/install_minimal_environment.sh @@ -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 + +# Install bazel diff --git a/dev/docker/installers/install_training_support.sh b/dev/docker/installers/install_training_support.sh new file mode 100644 index 0000000..0471e50 --- /dev/null +++ b/dev/docker/installers/install_training_support.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +pip install --upgrade numpy torch accelerate triton torchvision transformers huggingface_hub \ No newline at end of file diff --git a/playground.sh b/playground.sh new file mode 100755 index 0000000..3ef3a63 --- /dev/null +++ b/playground.sh @@ -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 "$@" \ No newline at end of file diff --git a/scripts/common.bashrc b/scripts/common.bashrc new file mode 100644 index 0000000..e69de29 diff --git a/scripts/playground.bashrc b/scripts/playground.bashrc new file mode 100644 index 0000000..c375a53 --- /dev/null +++ b/scripts/playground.bashrc @@ -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 +} \ No newline at end of file diff --git a/scripts/start_dev_docker.sh b/scripts/start_dev_docker.sh new file mode 100755 index 0000000..05a7907 --- /dev/null +++ b/scripts/start_dev_docker.sh @@ -0,0 +1,2 @@ +#!/bin/bash +