Skip to content

Commit 978e7a3

Browse files
OPEA Code Generation Example (#41)
* OPEA Code Generation Example * Fix link
1 parent 2b559b5 commit 978e7a3

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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) Code Generation Example
10+
11+
This demo will showcase Code Generation CPU inference using 5th Gen Xeon Scalable Processors on GCP using the OPEA CodeGen 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/CodeGen)
12+
13+
## Usage
14+
15+
## After cloning the repo, modify /examples/gen-ai-xeon-opea-codegen/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-codegen/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-codegen
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 CodeGen: `http://yourpublicip:5174`
55+
- Additional Instructions on how to setup VScode CodeGen integration can be found [**here**](https://github.com/opea-project/GenAIExamples/blob/main/CodeGen/docker_compose/intel/cpu/xeon/README.md#install-copilot-vscode-extension-from-plugin-marketplace-as-the-frontend)
56+
57+
58+
## Deleting the Demo
59+
60+
To delete the demo, run `terraform destroy` to delete all resources created.
61+
62+
## Pre-requisites for running on a local Workstation (disregard if using GCP Cloud Shell)
63+
64+
1. Google Cloud CLI: https://cloud.google.com/sdk/docs/install
65+
2. CGP account access configured: https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference.html#running-terraform-on-your-workstation
66+
3. Terraform: https://learn.hashicorp.com/tutorials/terraform/install-cli
67+
4. Git: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
68+
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-codegen-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 Code Generation
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 = "ai-opea-codegen-${random_id.rid.dec}"
13+
zone = "us-east4-a"
14+
machine_type = "c4-highcpu-48"
15+
allow_stopping_for_update = true
16+
tags = ["ai-opea-codegen-${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 = "ai-opea-codegen-${random_id.rid.dec}"
29+
network = "default"
30+
description = "Allows access to OPEA AI Code Generation"
31+
32+
allow {
33+
protocol = "tcp"
34+
ports = ["22", "80", "443", "6379", "8001", "6006", "6007", "6000", "7000", "8808", "8000", "8888", "5173", "5174", "9009", "9000", "8028", "7778"]
35+
}
36+
source_ranges = ["0.0.0.0/0"]
37+
target_tags = ["ai-opea-codegen-${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 = "<Enter your GCP project ID>"
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 = "<YOUR HUGGINGFACE TOKEN>"
11+
type = string
12+
}

0 commit comments

Comments
 (0)