From e001ce93e6623aa40cecf58e403f5e7292dc67a0 Mon Sep 17 00:00:00 2001 From: Anuradha Karuppiah Date: Tue, 24 Sep 2024 21:11:44 +0000 Subject: [PATCH] Conda recipe for generating the morpheus-llm package Signed-off-by: Anuradha Karuppiah --- .../morpheus-llm/conda_build_config.yaml | 32 +++++++ ci/conda/recipes/morpheus-llm/meta.yaml | 87 ++++++++++++++++++ .../morpheus-llm/morpheus_llm_build.sh | 92 +++++++++++++++++++ ci/conda/recipes/run_conda_build.sh | 10 ++ ci/scripts/github/conda_llm.sh | 61 ++++++++++++ ci/scripts/run_ci_local.sh | 6 +- 6 files changed, 285 insertions(+), 3 deletions(-) create mode 100644 ci/conda/recipes/morpheus-llm/conda_build_config.yaml create mode 100644 ci/conda/recipes/morpheus-llm/meta.yaml create mode 100644 ci/conda/recipes/morpheus-llm/morpheus_llm_build.sh create mode 100755 ci/scripts/github/conda_llm.sh diff --git a/ci/conda/recipes/morpheus-llm/conda_build_config.yaml b/ci/conda/recipes/morpheus-llm/conda_build_config.yaml new file mode 100644 index 0000000000..4b051dc074 --- /dev/null +++ b/ci/conda/recipes/morpheus-llm/conda_build_config.yaml @@ -0,0 +1,32 @@ +# SPDX-FileCopyrightText: Copyright (c) 2021-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +c_compiler_version: + - 11.2 + +cxx_compiler_version: + - 11.2 + +cuda_compiler: + - cuda-nvcc + +cuda_compiler_version: + - 12.1 + +python: + - 3.10 + +rapids_version: + - 24.02 diff --git a/ci/conda/recipes/morpheus-llm/meta.yaml b/ci/conda/recipes/morpheus-llm/meta.yaml new file mode 100644 index 0000000000..fc018601d4 --- /dev/null +++ b/ci/conda/recipes/morpheus-llm/meta.yaml @@ -0,0 +1,87 @@ +# SPDX-FileCopyrightText: Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +{% set version = environ.get('GIT_VERSION', '0.0.0.dev').lstrip('v') + environ.get('VERSION_SUFFIX', '') %} +{% set minor_version = version.split('.')[0] + '.' + version.split('.')[1] %} + +package: + name: morpheus-llm + version: {{ version }} + +source: + git_url: ../../../.. + +outputs: + + - name: morpheus-llm + build: + number: {{ GIT_DESCRIBE_NUMBER }} + string: cuda_{{ cuda_compiler_version }}_py{{ python }}_{{ GIT_DESCRIBE_HASH }}_{{ GIT_DESCRIBE_NUMBER }} + script_env: + # Note: Setting a default value here will overwrite the value from the + # shell! Defaults should be set in the run_conda_build.sh script + - CMAKE_CUDA_ARCHITECTURES + - MORPHEUS_CACHE_DIR + - MORPHEUS_PYTHON_BUILD_STUBS + - PARALLEL_LEVEL + run_exports: + - {{ pin_subpackage("morpheus-llm", max_pin="x.x") }} + script: morpheus_llm_build.sh + + requirements: + build: + - {{ compiler("c") }} + - {{ compiler("cuda") }} + - {{ compiler("cxx") }} + - ccache + - cmake =3.27 + - ninja =1.11 + host: + - cudf {{ rapids_version }} + - cython 3.0.* + - glog 0.6.* + - libcudf {{ rapids_version }} + - librdkafka >=1.9.2,<1.10.0a0 + - morpheus-core {{ minor_version }} + - pip + - pybind11-stubgen 0.10.5 + - python {{ python }} + - rapidjson 1.1.0 + - scikit-build 0.17.6 + - versioneer-518 + - zlib 1.2.13 # required to build triton client + run: + - morpheus-core {{ minor_version }} + test: + requires: + - pynvml + - pytest-asyncio + - pytest-benchmark + - pytest-cov + - pytest =7.4.4 + source_files: + - pyproject.toml + - scripts/fetch_data.py + imports: + - morpheus_llm + commands: + - echo # make sure test requirements get installed + +about: + home: https://github.com/nv-morpheus/Morpheus + license: Apache-2.0 + license_family: Apache + license_file: LICENSE + summary: Morpheus Cybersecurity LLM Library diff --git a/ci/conda/recipes/morpheus-llm/morpheus_llm_build.sh b/ci/conda/recipes/morpheus-llm/morpheus_llm_build.sh new file mode 100644 index 0000000000..52ce520b52 --- /dev/null +++ b/ci/conda/recipes/morpheus-llm/morpheus_llm_build.sh @@ -0,0 +1,92 @@ +# SPDX-FileCopyrightText: Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# It is assumed that this script is executed from the root of the repo directory by conda-build +# (https://conda-forge.org/docs/maintainer/knowledge_base.html#using-cmake) + +# This will store all of the cmake args. Make sure to prepend args to allow +# incoming values to overwrite them +CMAKE_ARGS=${CMAKE_ARGS:-""} + +export CCACHE_BASEDIR=$(realpath ${SRC_DIR}/..) +export USE_SCCACHE=${USE_SCCACHE:-""} + +# Check for some mrc environment variables. Append to front of args to allow users to overwrite them +if [[ -n "${MORPHEUS_CACHE_DIR}" ]]; then + # Set the cache variable, then set the Staging prefix to allow for host searching + CMAKE_ARGS="-DMORPHEUS_CACHE_DIR=${MORPHEUS_CACHE_DIR} ${CMAKE_ARGS}" + + # Double check that the cache dir has been created + mkdir -p ${MORPHEUS_CACHE_DIR} +fi + +# Enable llm +CMAKE_ARGS="-DMORPHEUS_BUILD_MORPHEUS_LLM=ON ${CMAKE_ARGS}" + +# Disable core, dfp and doca +CMAKE_ARGS="-DMORPHEUS_SUPPORT_DOCA=OFF ${CMAKE_ARGS}" +CMAKE_ARGS="-DMORPHEUS_BUILD_MORPHEUS_CORE=OFF ${CMAKE_ARGS}" +CMAKE_ARGS="-DMORPHEUS_BUILD_MORPHEUS_DFP=OFF ${CMAKE_ARGS}" + +CMAKE_ARGS="-DCMAKE_MESSAGE_CONTEXT_SHOW=ON ${CMAKE_ARGS}" +CMAKE_ARGS="-DCMAKE_INSTALL_PREFIX=$PREFIX ${CMAKE_ARGS}" +CMAKE_ARGS="-DCMAKE_INSTALL_LIBDIR=lib ${CMAKE_ARGS}" +CMAKE_ARGS="-DBUILD_SHARED_LIBS=ON ${CMAKE_ARGS}" +CMAKE_ARGS="-DMORPHEUS_USE_CONDA=ON ${CMAKE_ARGS}" +CMAKE_ARGS="-DMORPHEUS_USE_CCACHE=ON ${CMAKE_ARGS}" +CMAKE_ARGS="-DMORPHEUS_PYTHON_BUILD_STUBS=${MORPHEUS_PYTHON_BUILD_STUBS=-"ON"} ${CMAKE_ARGS}" +CMAKE_ARGS="-DMORPHEUS_PYTHON_INPLACE_BUILD=ON ${CMAKE_ARGS}" +CMAKE_ARGS="-DMORPHEUS_PYTHON_BUILD_WHEEL=ON ${CMAKE_ARGS}" +CMAKE_ARGS="-DCMAKE_BUILD_RPATH_USE_ORIGIN=ON ${CMAKE_ARGS}" +CMAKE_ARGS="-DCMAKE_CUDA_ARCHITECTURES=${CMAKE_CUDA_ARCHITECTURES=-"RAPIDS"} ${CMAKE_ARGS}" +CMAKE_ARGS="-DPython_EXECUTABLE=${PYTHON} ${CMAKE_ARGS}" +CMAKE_ARGS="-DPYTHON_EXECUTABLE=${PYTHON} ${CMAKE_ARGS}" # for pybind11 +CMAKE_ARGS="--log-level=VERBOSE ${CMAKE_ARGS}" + +if [[ "${USE_SCCACHE}" == "1" ]]; then + CMAKE_ARGS="-DCCACHE_PROGRAM_PATH=$(which sccache) ${CMAKE_ARGS}" +fi + +echo "CC : ${CC}" +echo "CXX : ${CXX}" +echo "CUDAHOSTCXX : ${CUDAHOSTCXX}" +echo "CUDA : ${CUDA}" +echo "CMAKE_ARGS : ${CMAKE_ARGS}" + +echo "========Begin Env========" +env +echo "========End Env========" + +BUILD_DIR="build-conda" + +# Check if the build directory already exists. And if so, delete the +# CMakeCache.txt and CMakeFiles to ensure a clean configuration +if [[ -d "./${BUILD_DIR}" ]]; then + echo "Deleting old CMake files at ./${BUILD_DIR}" + rm -rf "./${BUILD_DIR}/CMakeCache.txt" + rm -rf "./${BUILD_DIR}/CMakeFiles" +fi + +# Run configure +cmake -B ${BUILD_DIR} \ + ${CMAKE_ARGS} \ + --log-level=verbose \ + . + +# Build the components +cmake --build ${BUILD_DIR} -j${PARALLEL_LEVEL:-$(nproc)} --target install + +# Install just the mprpheus llm python wheel components +${PYTHON} -m pip install -vv ${BUILD_DIR}/python/morpheus_llm/dist/*.whl diff --git a/ci/conda/recipes/run_conda_build.sh b/ci/conda/recipes/run_conda_build.sh index 6900d8b993..7f07a068fd 100755 --- a/ci/conda/recipes/run_conda_build.sh +++ b/ci/conda/recipes/run_conda_build.sh @@ -164,6 +164,16 @@ if hasArg morpheus-dfp; then set +x fi +if hasArg morpheus-llm; then + # Set GIT_VERSION to set the project version inside of meta.yaml + export GIT_VERSION="$(get_version)" + + echo "Running conda-build for morpheus-llm v${GIT_VERSION}..." + set -x + conda ${CONDA_COMMAND} "${CONDA_ARGS_ARRAY[@]}" ${CONDA_ARGS} ci/conda/recipes/morpheus-llm + set +x +fi + if hasArg pydebug; then export MORPHEUS_PYTHON_VER=$(python --version | cut -d ' ' -f 2) diff --git a/ci/scripts/github/conda_llm.sh b/ci/scripts/github/conda_llm.sh new file mode 100755 index 0000000000..85dc71b4ef --- /dev/null +++ b/ci/scripts/github/conda_llm.sh @@ -0,0 +1,61 @@ +#!/usr/bin/bash +# SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +CI_SCRIPT_ARGS="$@" +source ${WORKSPACE}/ci/scripts/github/common.sh + +cd ${MORPHEUS_ROOT} + +fetch_base_branch + +# Its important that we are in the base environment for the build +rapids-logger "Activating Base Conda Environment" + +# Deactivate any extra environments (There can be a few on the stack) +while [[ "${CONDA_SHLVL:-0}" -gt 1 ]]; do + echo "Deactivating conda environment ${CONDA_DEFAULT_ENV}" + conda deactivate +done + +# Ensure at least base is activated +if [[ "${CONDA_DEFAULT_ENV}" != "base" ]]; then + echo "Activating base conda environment" + conda activate base +fi + +# Print the info just to be sure base is active +conda info + +rapids-logger "Building Conda Package morpheus-llm" + +# Run the conda build, and upload to conda forge if requested +export MORPHEUS_PYTHON_BUILD_STUBS=OFF +export CONDA_ARGS="--skip-existing" +${MORPHEUS_ROOT}/ci/conda/recipes/run_conda_build.sh morpheus-llm "${CI_SCRIPT_ARGS}" + +# If we didn't receive the upload argument, upload the artifact to S3 +if [[ " ${CI_SCRIPT_ARGS} " =~ " upload " ]]; then + rapids-logger "Building Conda Package morpheus-llm... Done" +else + # if we didn't receive the upload argument, we can still upload the artifact to S3 + tar cfj "${WORKSPACE_TMP}/conda_morpheus_llm.tar.bz" "${RAPIDS_CONDA_BLD_OUTPUT_DIR}" + ls -lh ${WORKSPACE_TMP}/ + + rapids-logger "Pushing results to ${DISPLAY_ARTIFACT_URL}/" + upload_artifact "${WORKSPACE_TMP}/conda_morpheus_llm.tar.bz" +fi diff --git a/ci/scripts/run_ci_local.sh b/ci/scripts/run_ci_local.sh index ff1a717733..634714addc 100755 --- a/ci/scripts/run_ci_local.sh +++ b/ci/scripts/run_ci_local.sh @@ -21,13 +21,13 @@ case "$1" in STAGES=("bash") ;; "all" ) - STAGES=("checks" "build" "docs" "test" "conda_core" "conda_dfp" "conda") + STAGES=("checks" "build" "docs" "test" "conda_core" "conda_dfp" "conda_llm" "conda") ;; - "checks" | "build" | "docs" | "test" | "conda_core" | "conda_dfp" | "conda" | "bash" ) + "checks" | "build" | "docs" | "test" | "conda_core" | "conda_dfp" | "conda_llm" | "conda" | "bash" ) STAGES=("$1") ;; * ) - echo "Error: Invalid argument \"$1\" provided. Expected values: \"all\", \"checks\", \"build\", \"docs\", \"test\", \"conda_core\", \"conda_dfp\", \"conda\", or \"bash\"" + echo "Error: Invalid argument \"$1\" provided. Expected values: \"all\", \"checks\", \"build\", \"docs\", \"test\", \"conda_core\", \"conda_dfp\", \"conda_llm\", \"conda\", or \"bash\"" exit 1 ;; esac