Skip to content

Commit 6164de9

Browse files
Add OPEA ChatQna example
1 parent 68a2600 commit 6164de9

File tree

7 files changed

+140
-4
lines changed

7 files changed

+140
-4
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<p align="center">
2+
<img src="https://github.com/intel/terraform-intel-gcp-vm/blob/main/images/logo-classicblue-800px.png?raw=true" alt="Intel Logo" width="250"/>
3+
</p>
4+
5+
# Intel® Optimized Cloud Modules for Terraform
6+
7+
© Copyright 2024, Intel Corporation
8+
9+
## GCP C4 Instance with 5th Generation Intel® Xeon® Scalable Processor (Emerald Rapids) & Open Platform for Enterprise AI (OPEA) ChatQnA Example
10+
11+
This demo will showcase Retrieval Augmented Generation (RAG) CPU inference using 5th Gen Xeon Scalable Processors on GCP using the OPEA ChatQnA Example. For more information about OPEA, go [here](https://opea.dev/). For more information on this specific example, go [here](https://github.com/opea-project/GenAIExamples/tree/main/ChatQnA).
12+
13+
## Usage
14+
15+
## After cloning the repo, modify /examples/gen-ai-xeon-opea-chatqna/variables.tf to add your Huggingface Token
16+
17+
Some Models required a Token. Modify the Huggingface Token variable to your specific Huggingface Token, for information on creating a Huggingface token go [here](https://huggingface.co/docs/hub/en/security-tokens)
18+
19+
```hcl
20+
variable "huggingface_token" {
21+
description = "Huggingface Token"
22+
default = " <YOUR HUGGINGFACE TOKEN> "
23+
type = string
24+
}
25+
```
26+
27+
**If needed, also modify values on /examples/gen-ai-xeon-opea-chatqna/main.tf to match your needs**
28+
29+
## GCP Cloud Shell Usage
30+
31+
1. Log on to GCP Portal
32+
2. Enter the GCP Cloud Shell (terminal button on top right of page)
33+
3. Run the following commands in order:
34+
35+
36+
```bash
37+
git clone https://github.com/intel/terraform-intel-gcp-vm.git
38+
cd terraform-intel-gcp-vm/examples/gen-ai-xeon-opea-chatqna
39+
# ADD TOKEN TO variables.tf (SEE ABOVE)
40+
terraform init
41+
terraform plan
42+
terraform apply
43+
44+
# (enter your GCP project ID and "yes" to confirm)
45+
46+
```
47+
48+
After the Terraform module successfully creates the GCP VM instance, **wait ~15 minutes** for the module to launch the containers and download the LLMs before continuing.
49+
50+
## Accessing the Demo
51+
52+
You can access the demos using the following:
53+
54+
- OPEA ChatQnA: `http://yourpublicip:5174`
55+
56+
57+
## Deleting the Demo
58+
59+
To delete the demo, run `terraform destroy` to delete all resources created.
60+
61+
## Pre-requisites for running on a local Workstation (disregard if using GCP Cloud Shell)
62+
63+
1. Google Cloud CLI: https://cloud.google.com/sdk/docs/install
64+
2. CGP account access configured: https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference.html#running-terraform-on-your-workstation
65+
3. Terraform: https://learn.hashicorp.com/tutorials/terraform/install-cli
66+
4. Git: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#cloud-config
2+
package_update: true
3+
package_upgrade: true
4+
5+
package:
6+
- git
7+
8+
runcmd:
9+
- apt install ansible -y
10+
- git clone https://github.com/intel/optimized-cloud-recipes.git /tmp/optimized-cloud-recipes
11+
- cd /tmp/optimized-cloud-recipes/recipes/ai-opea-chatqna-xeon
12+
- cp opea.sh /etc/profile.d/opea.sh
13+
- echo 'export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}' | sudo tee -a /etc/profile.d/opea.sh
14+
- chmod +x /etc/profile.d/opea.sh
15+
- source /etc/profile.d/opea.sh
16+
- ansible-playbook recipe.yml
17+
18+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#Random ID to minimize the chances of name conflicts
2+
resource "random_id" "rid" {
3+
byte_length = 3
4+
}
5+
6+
#GCP Linux VM with Intel OPEA ChatQnA
7+
module "linux_vm" {
8+
source = "../.." #intel/gcp-vm/intel
9+
project = var.project
10+
boot_image_project = "ubuntu-os-cloud"
11+
boot_image_family = "ubuntu-2204-lts"
12+
name = "lmelo-ai-opea-chatqna-${random_id.rid.dec}"
13+
zone = "us-east4-a" #"us-central1-a"
14+
machine_type = "c4-highcpu-48"
15+
allow_stopping_for_update = true
16+
tags = ["lmelo-ai-opea-chatqna-${random_id.rid.dec}"]
17+
user_data = templatefile("./cloud_init.yml", { HUGGINGFACEHUB_API_TOKEN = var.huggingface_token })
18+
access_config = [{
19+
nat_ip = null
20+
public_ptr_domain_name = null
21+
network_tier = "PREMIUM"
22+
}, ]
23+
}
24+
25+
#Required firewall rules
26+
resource "google_compute_firewall" "rules" {
27+
project = var.project
28+
name = "lmelo-ai-opea-chatqna-${random_id.rid.dec}"
29+
network = "default"
30+
description = "Allows access to OPEA AI ChatQnA"
31+
32+
allow {
33+
protocol = "tcp"
34+
ports = ["22","80", "443", "6379", "8001", "6006", "6007", "6000", "7000", "8808", "8000", "8888", "5173", "5174", "9009", "9000"]
35+
}
36+
source_ranges = ["0.0.0.0/0"]
37+
target_tags = ["lmelo-ai-opea-chatqna-${random_id.rid.dec}"]
38+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
variable "project" {
2+
type = string
3+
default = "551221341017"
4+
description = "Enter GCP Project ID"
5+
}
6+
7+
# Variable for Huggingface Token
8+
variable "huggingface_token" {
9+
description = "Enter a Huggingface Token to be used to download the models"
10+
default = "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"
11+
type = string
12+
}

main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
# Intel CPU, we are not populating the min CPU platform. We are using the default CPU platform that GCP will provide for these older generation of instances
88

99
locals {
10-
machine_type_regex = "^([cemn][123u])"
10+
machine_type_regex = "^([cemn][1234u])"
1111
machine_types = {
1212
"n2": "Intel Ice Lake",
1313
"c3": "Intel Sapphire Rapids",
1414
"m3": "Intel Ice Lake",
1515
"c2": "Intel Cascade Lake"
16+
"c4": null
17+
"n4": null
1618
"n1": null
1719
"m1": null
1820
"m2": null

variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ variable "boot_image_family" {
103103
variable "boot_disk_size" {
104104
type = number
105105
description = "Size of the OS disk"
106-
default = 100
106+
default = 500
107107
}
108108

109109
variable "boot_disk_type" {
110110
type = string
111111
description = "Disk type associated with the OS disk. Values can be either pd-ssd, local-ssd, or pd-standard"
112-
default = "pd-ssd"
112+
default = null
113113
}
114114

115115
variable "boot_image_project" {

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
google = {
66
source = "hashicorp/google"
7-
version = "~> 5.11"
7+
version = "~> 6.5"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)