Skip to content

Commit

Permalink
Merge branch 'main' into mb-exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
Yugar-1 authored Sep 5, 2024
2 parents a736170 + 0094f52 commit 3447279
Show file tree
Hide file tree
Showing 49 changed files with 1,137 additions and 78 deletions.
43 changes: 39 additions & 4 deletions .github/workflows/pr-go-unittests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
paths:
- microservices-connector/**
- kubernetes-addons/memory-bandwidth-exporter/**
- "!microservices-connector/helm/**"
- "!**.md"
- "!**.txt"
Expand All @@ -21,11 +22,45 @@ concurrency:
cancel-in-progress: true

env:
GOSRC_DIR: "microservices-connector"
GMC_DIR: "microservices-connector"
MBE_DIR: "kubernetes-addons/memory-bandwidth-exporter"

jobs:
job1:
name: Get-test-matrix
runs-on: ubuntu-latest
outputs:
run_matrix: ${{ steps.get-test-matrix.outputs.run_matrix }}
steps:
- name: Checkout out Repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get test matrix
id: get-test-matrix
run: |
set -xe
base_commit=${{ github.event.pull_request.base.sha }}
merged_commit=${{ github.event.pull_request.head.sha }}
run_matrix="["
if git diff --name-only ${base_commit} ${merged_commit} | grep -q "^${GMC_DIR}/"; then
run_matrix="${run_matrix}\"${GMC_DIR}\","
fi
if git diff --name-only ${base_commit} ${merged_commit} | grep -q "^${MBE_DIR}/"; then
run_matrix="${run_matrix}\"${MBE_DIR}\","
fi
run_matrix=${run_matrix%,}"]"
echo "run_matrix=${run_matrix}"
echo "run_matrix=${run_matrix}" >> $GITHUB_OUTPUT
go-unittests:
needs: [job1]
runs-on: ubuntu-latest
if: always() && ${{ needs.job1.outputs.run_matrix.length }} > 0
strategy:
matrix:
gopath: ${{ fromJSON(needs.job1.outputs.run_matrix) }}
permissions:
contents: write
actions: write
Expand All @@ -47,18 +82,18 @@ jobs:
with:
args: --timeout=10m
version: v1.55.2
working-directory: ${{ env.GOSRC_DIR }}
working-directory: ${{ matrix.gopath }}

- name: Run golangunit test
run: |
cd $GOSRC_DIR
cd ${{ matrix.gopath }}
make test
- name: Run tests and generate coverage
run: |
if [ "${{ matrix.gopath }}" == "${MBE_DIR}" ]; then
exit 0
fi
cd $GOSRC_DIR
cd ${{ matrix.gopath }}
go test -coverprofile=coverage.out $(go list ./... | grep -v /e2e)
${{ github.workspace }}/.github/workflows/scripts/go-coverage.sh
9 changes: 9 additions & 0 deletions helm-charts/chatqna/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ name: chatqna
description: The Helm chart to deploy ChatQnA
type: application
dependencies:
- name: tgi
version: 1.0.0
alias: tgi-guardrails
repository: "file://../common/tgi"
condition: guardrails-usvc.enabled
- name: guardrails-usvc
version: 1.0.0
repository: "file://../common/guardrails-usvc"
condition: guardrails-usvc.enabled
- name: tgi
version: 1.0.0
repository: "file://../common/tgi"
Expand Down
4 changes: 4 additions & 0 deletions helm-charts/chatqna/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ helm install chatqna chatqna --set global.HUGGINGFACEHUB_API_TOKEN=${HFTOKEN} --
#helm install chatqna chatqna --set global.HUGGINGFACEHUB_API_TOKEN=${HFTOKEN} --set global.modelUseHostPath=${MODELDIR} --set tgi.LLM_MODEL_ID=${MODELNAME} -f chatqna/gaudi-values.yaml
# To use Nvidia GPU
#helm install chatqna chatqna --set global.HUGGINGFACEHUB_API_TOKEN=${HFTOKEN} --set global.modelUseHostPath=${MODELDIR} --set tgi.LLM_MODEL_ID=${MODELNAME} -f chatqna/nv-values.yaml
# To include guardrail component in chatqna on Xeon
#helm install chatqna chatqna --set global.HUGGINGFACEHUB_API_TOKEN=${HFTOKEN} --set global.modelUseHostPath=${MODELDIR} -f chatqna/guardrails-values.yaml
# To include guardrail component in chatqna on Gaudi
#helm install chatqna chatqna --set global.HUGGINGFACEHUB_API_TOKEN=${HFTOKEN} --set global.modelUseHostPath=${MODELDIR} -f chatqna/guardrails-gaudi-values.yaml
```

### IMPORTANT NOTE
Expand Down
46 changes: 46 additions & 0 deletions helm-charts/chatqna/guardrails-gaudi-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

image:
repository: opea/chatqna-guardrails
tag: "latest"

# guardrails related config
guardrails-usvc:
enabled: true
SAFETY_GUARD_ENDPOINT: "http://{{ .Release.Name }}-tgi-guardrails"
SAFETY_GUARD_MODEL_ID: "meta-llama/Meta-Llama-Guard-2-8B"

# gaudi related config
tei:
image:
repository: ghcr.io/huggingface/tei-gaudi
tag: synapse_1.16
resources:
limits:
habana.ai/gaudi: 1
securityContext:
readOnlyRootFilesystem: false

tgi:
image:
repository: ghcr.io/huggingface/tgi-gaudi
tag: "2.0.1"
resources:
limits:
habana.ai/gaudi: 1
MAX_INPUT_LENGTH: "1024"
MAX_TOTAL_TOKENS: "2048"
CUDA_GRAPHS: ""

tgi-guardrails:
LLM_MODEL_ID: "meta-llama/Meta-Llama-Guard-2-8B"
image:
repository: ghcr.io/huggingface/tgi-gaudi
tag: "2.0.1"
resources:
limits:
habana.ai/gaudi: 1
MAX_INPUT_LENGTH: "1024"
MAX_TOTAL_TOKENS: "2048"
CUDA_GRAPHS: ""
14 changes: 14 additions & 0 deletions helm-charts/chatqna/guardrails-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

image:
repository: opea/chatqna-guardrails
tag: "latest"

# guardrails related config
guardrails-usvc:
enabled: true
SAFETY_GUARD_ENDPOINT: "http://{{ .Release.Name }}-tgi-guardrails"
SAFETY_GUARD_MODEL_ID: "meta-llama/Meta-Llama-Guard-2-8B"
tgi-guardrails:
LLM_MODEL_ID: "meta-llama/Meta-Llama-Guard-2-8B"
2 changes: 2 additions & 0 deletions helm-charts/chatqna/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ spec:
value: {{ .Release.Name }}-retriever-usvc
- name: EMBEDDING_SERVICE_HOST_IP
value: {{ .Release.Name }}-embedding-usvc
- name: GUARDRAIL_SERVICE_HOST_IP
value: {{ .Release.Name }}-guardrails-usvc
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
Expand Down
5 changes: 5 additions & 0 deletions helm-charts/chatqna/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ affinity: {}
tgi:
LLM_MODEL_ID: Intel/neural-chat-7b-v3-3

# disable guardrails-usvc by default
# See guardrails-values.yaml for guardrail related options
guardrails-usvc:
enabled: false

global:
http_proxy: ""
https_proxy: ""
Expand Down
3 changes: 0 additions & 3 deletions helm-charts/common/data-prep/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,4 @@ data:
{{- else }}
no_proxy: {{ .Values.global.no_proxy | quote }}
{{- end }}
LANGCHAIN_TRACING_V2: {{ .Values.global.LANGCHAIN_TRACING_V2 | quote }}
LANGCHAIN_API_KEY: {{ .Values.global.LANGCHAIN_API_KEY | quote }}
LANGCHAIN_PROJECT: "opea-dataprep-service"
LOGFLAG: {{ .Values.LOGFLAG | quote }}
2 changes: 0 additions & 2 deletions helm-charts/common/data-prep/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,3 @@ global:
https_proxy: ""
no_proxy: ""
HUGGINGFACEHUB_API_TOKEN: "insert-your-huggingface-token-here"
LANGCHAIN_TRACING_V2: false
LANGCHAIN_API_KEY: "insert-your-langchain-key-here"
3 changes: 0 additions & 3 deletions helm-charts/common/embedding-usvc/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,4 @@ data:
{{- else }}
no_proxy: {{ .Values.global.no_proxy | quote }}
{{- end }}
LANGCHAIN_TRACING_V2: {{ .Values.global.LANGCHAIN_TRACING_V2 | quote }}
LANGCHAIN_API_KEY: {{ .Values.global.LANGCHAIN_API_KEY }}
LANGCHAIN_PROJECT: "opea-embedding-service"
LOGFLAG: {{ .Values.LOGFLAG | quote }}
6 changes: 0 additions & 6 deletions helm-charts/common/embedding-usvc/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,3 @@ global:
http_proxy: ""
https_proxy: ""
no_proxy: ""
# HUGGINGFACEHUB_API_TOKEN: "insert-your-huggingface-token-here"
LANGCHAIN_TRACING_V2: false
LANGCHAIN_API_KEY: "insert-your-langchain-key-here"
# set modelUseHostPath to host directory if you want to use hostPath volume for model storage
# comment out modeluseHostPath if you want to download the model from huggingface
modelUseHostPath: /mnt/opea-models
23 changes: 23 additions & 0 deletions helm-charts/common/guardrails-usvc/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
14 changes: 14 additions & 0 deletions helm-charts/common/guardrails-usvc/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

apiVersion: v2
name: guardrails-usvc
description: The Helm chart for deploying guardrails-usvc as microservice
type: application
version: 1.0.0
appVersion: "v1.0"
dependencies:
- name: tgi
version: 1.0.0
repository: file://../tgi
condition: autodependency.enabled
57 changes: 57 additions & 0 deletions helm-charts/common/guardrails-usvc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# guardrails-usvc

Helm chart for deploying LLM microservice.

guardrails-usvc depends on TGI, you should set TGI_LLM_ENDPOINT as tgi endpoint.

## (Option1): Installing the chart separately:

First, you need to install the tgi chart, please refer to the [tgi](../tgi) chart for more information. Please use model `meta-llama/Meta-Llama-Guard-2-8B` during installation.

After you've deployted the tgi chart successfully, please run `kubectl get svc` to get the tgi service endpoint, i.e. `http://tgi`.

To install the chart, run the following:

```console
cd GenAIInfra/helm-charts/common/guardrails-usvc
export HFTOKEN="insert-your-huggingface-token-here"
export SAFETY_GUARD_ENDPOINT="http://tgi"
export SAFETY_GUARD_MODEL_ID="meta-llama/Meta-Llama-Guard-2-8B"
helm dependency update
helm install guardrails-usvc . --set global.HUGGINGFACEHUB_API_TOKEN=${HFTOKEN} --set SAFETY_GUARD_ENDPOINT=${SAFETY_GUARD_ENDPOINT} --set SAFETY_GUARD_MODEL_ID=${SAFETY_GUARD_MODEL_ID} --wait
```

## (Option2): Installing the chart with dependencies automatically:

```console
cd GenAIInfra/helm-charts/common/guardrails-usvc
export HFTOKEN="insert-your-huggingface-token-here"
helm dependency update
helm install guardrails-usvc . --set global.HUGGINGFACEHUB_API_TOKEN=${HFTOKEN} --set autodependency.enabled=true --wait
```

## Verify

To verify the installation, run the command `kubectl get pod` to make sure all pods are running.

Then run the command `kubectl port-forward svc/guardrails-usvc 9090:9090` to expose the llm-uservice service for access.

Open another terminal and run the following command to verify the service if working:

```console
curl http://localhost:9090/v1/guardrails \
-X POST \
-d '{"text":"How do you buy a tiger in the US?","parameters":{"max_new_tokens":32}}' \
-H 'Content-Type: application/json'
```

## Values

| Key | Type | Default | Description |
| ------------------------------- | ------ | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| global.HUGGINGFACEHUB_API_TOKEN | string | `""` | Your own Hugging Face API token |
| global.modelUseHostPath | string | `"/mnt/opea-models"` | Cached models directory, tgi will not download if the model is cached here. The host path "modelUseHostPath" will be mounted to container as /data directory |
| image.repository | string | `"opea/guardrails-usvc"` | |
| service.port | string | `"9090"` | |
| SAFETY_GUARD_ENDPOINT | string | `""` | LLM endpoint |
| SAFETY_GUARD_MODEL_ID | string | `"meta-llama/Meta-Llama-Guard-2-8B"` | Model ID for the underlying LLM service is using |
62 changes: 62 additions & 0 deletions helm-charts/common/guardrails-usvc/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "guardrails-usvc.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "guardrails-usvc.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "guardrails-usvc.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "guardrails-usvc.labels" -}}
helm.sh/chart: {{ include "guardrails-usvc.chart" . }}
{{ include "guardrails-usvc.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "guardrails-usvc.selectorLabels" -}}
app.kubernetes.io/name: {{ include "guardrails-usvc.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "guardrails-usvc.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "guardrails-usvc.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
Loading

0 comments on commit 3447279

Please sign in to comment.