• Stars
    star
    1,505
  • Rank 31,161 (Top 0.7 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created 12 months ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

localllm

Run LLMs locally on Cloud Workstations. Uses:

In this guide:

Running as a Cloud Workstation

This repository includes a Dockerfile that can be used to create a custom base image for a Cloud Workstation environment that includes the llm tool.

To get started, you'll need to have a GCP Project and have the gcloud CLI installed.

  1. Set environment variables

    1. Set the PROJECT_ID and PROJECT_NUM environment variables from your GCP project. You must modify the values.

      export PROJECT_ID=<project-id>
      export PROJECT_NUM=<project-num>
    2. Set other needed environment variables. You can modify the values.

      export REGION=us-central1
      export LOCALLLM_REGISTRY=localllm-registry
      export LOCALLLM_IMAGE_NAME=localllm
      export LOCALLLM_CLUSTER=localllm-cluster
      export LOCALLLM_WORKSTATION=localllm-workstation
      export LOCALLLM_PORT=8000
  2. Set the default project.

    gcloud config set project $PROJECT_ID
  3. Enable needed services.

    gcloud services enable \
      cloudbuild.googleapis.com \
      workstations.googleapis.com \
      container.googleapis.com \
      containeranalysis.googleapis.com \
      containerscanning.googleapis.com \
      artifactregistry.googleapis.com
  4. Create an Artifact Registry repository for docker images.

    gcloud artifacts repositories create $LOCALLLM_REGISTRY \
      --location=$REGION \
      --repository-format=docker
  5. Build and push the image to Artifact Registry using Cloud Build. Details are in cloudbuild.yaml.

    gcloud builds submit . \
        --substitutions=_IMAGE_REGISTRY=$LOCALLLM_REGISTRY,_IMAGE_NAME=$LOCALLLM_IMAGE_NAME
  6. Configure a Cloud Workstation cluster.

    gcloud workstations clusters create $LOCALLLM_CLUSTER \
      --region=$REGION
  7. Create a Cloud Workstation configuration. We suggest using a machine type of e2-standard-32 which has 32 vCPU, 16 core and 128 GB memory.

    gcloud workstations configs create $LOCALLLM_WORKSTATION \
    --region=$REGION \
    --cluster=$LOCALLLM_CLUSTER \
    --machine-type=e2-standard-32 \
    --container-custom-image=us-central1-docker.pkg.dev/${PROJECT_ID}/${LOCALLLM_REGISTRY}/${LOCALLLM_IMAGE_NAME}:latest
  8. Create a Cloud Workstation.

    gcloud workstations create $LOCALLLM_WORKSTATION \
    --cluster=$LOCALLLM_CLUSTER \
    --config=$LOCALLLM_WORKSTATION \
    --region=$REGION
  9. Grant access to the default Cloud Workstation service account.

    gcloud artifacts repositories add-iam-policy-binding $LOCALLLM_REGISTRY \
      --location=$REGION \
      --member=serviceAccount:service-$PROJECT_NUM@gcp-sa-workstationsvm.iam.gserviceaccount.com \
      --role=roles/artifactregistry.reader
  10. Start the workstation.

    gcloud workstations start $LOCALLLM_WORKSTATION \
      --cluster=$LOCALLLM_CLUSTER \
      --config=$LOCALLLM_WORKSTATION \
      --region=$REGION
  11. Connect to the workstation using ssh. Alternatively, you can connect to the workstation interactively in the browser.

    gcloud workstations ssh $LOCALLLM_WORKSTATION \
      --cluster=$LOCALLLM_CLUSTER \
      --config=$LOCALLLM_WORKSTATION \
      --region=$REGION
  12. Start serving the default model from the repo.

    llm run TheBloke/Llama-2-13B-Ensemble-v5-GGUF $LOCALLLM_PORT
  13. Get the hostname of the workstation using:

    gcloud workstations describe $LOCALLLM_WORKSTATION \
      --cluster=$LOCALLLM_CLUSTER \
      --config=$LOCALLLM_WORKSTATION \
      --region=$REGION
  14. Interact with the model by visiting the live OpenAPI documentation page: https://$LOCALLLM_PORT-$LLM_HOSTNAME/docs.

llm commands

Assumes that models are downloaded to ~/.cache/huggingface/hub/. This is the default cache path used by Hugging Face Hub library and only supports .gguf files.

If you're using models from TheBloke and you don't specify a filename, we'll attempt to use the model with 4 bit medium quantization, or you can specify a filename explicitly.

  1. List downloaded models.

    llm list
  2. List running models.

    llm ps
  3. Start serving models.

    1. Start serving the default model from the repo. Download if not present.

      llm run TheBloke/Llama-2-13B-Ensemble-v5-GGUF 8000
    2. Start serving a specific model. Download if not present.

      llm run TheBloke/Llama-2-13B-Ensemble-v5-GGUF --filename llama-2-13b-ensemble-v5.Q4_K_S.gguf 8000
  4. Stop serving models.

    1. Stop serving all models from the repo.

      llm kill TheBloke/Llama-2-13B-Ensemble-v5-GGUF
    2. Stop serving a specific model.

      llm kill TheBloke/Llama-2-13B-Ensemble-v5-GGUF --filename llama-2-13b-ensemble-v5.Q4_K_S.gguf
  5. Download models.

    1. Download the default model from the repo.
      llm pull TheBloke/Llama-2-13B-Ensemble-v5-GGUF
    2. Download a specific model from the repo.
      llm pull TheBloke/Llama-2-13B-Ensemble-v5-GGUF --filename llama-2-13b-ensemble-v5.Q4_K_S.gguf
  6. Remove models.

    1. Remove all models downloaded from the repo.

      llm rm TheBloke/Llama-2-13B-Ensemble-v5-GGUF
    2. Remove a specific model from the repo.

      llm rm TheBloke/Llama-2-13B-Ensemble-v5-GGUF --filename llama-2-13b-ensemble-v5.Q4_K_S.gguf

Running locally

  1. Install the tools.

    # Install the tools
    pip3 install openai
    pip3 install ./llm-tool/.
  2. Download and run a model.

    llm run TheBloke/Llama-2-13B-Ensemble-v5-GGUF 8000
  3. Try out a query. The default query is for a haiku about cats.

    python3 querylocal.py
  4. Interact with the Open API interface via the /docs extension. For the above, visit http://localhost:8000/docs.

Debugging

To assist with debugging, you can configure model startup to write logs to a log file by providing a yaml python logging configuration file (for example see llm_log_config.yaml):

llm run TheBloke/Llama-2-13B-Ensemble-v5-GGUF 8000 --log-config llm_log_config.yaml

If running from Cloud Workstations, logs from running models will be written to /var/log/locallm.log (llm_log_config.yaml is provided by default via the environment variable LOG_CONFIG within the image). You can follow the logs with:

tail -f /var/log/localllm.log

To run locally using the bundled log config:

sudo touch /var/log/localllm.log
sudo chown user:user /var/log/localllm.log # use your user and group
export LOG_CONFIG=$(pip show llm | grep Location | awk '{print $2}')/llm_log_config.yaml

llm run ...

If you are running multiple models, the logs from each will be written to the same file and interleaved.

LLM Disclaimer

This project imports freely available LLMs and makes them available from Cloud Workstations. We recommend independently verifying any content generated by the models. We do not assume any responsibility or liability for the use or interpretation of generated content.

More Repositories

1

microservices-demo

Sample cloud-first application with 10 microservices showcasing Kubernetes, Istio, and gRPC.
Go
16,790
star
2

terraformer

CLI tool to generate terraform files from existing infrastructure (reverse Terraform). Infrastructure to Code
Go
12,352
star
3

training-data-analyst

Labs and demos for courses for GCP Training (http://cloud.google.com/training).
Jupyter Notebook
7,867
star
4

python-docs-samples

Code samples used on cloud.google.com
Jupyter Notebook
7,432
star
5

generative-ai

Sample code and notebooks for Generative AI on Google Cloud, with Gemini on Vertex AI
Jupyter Notebook
6,517
star
6

golang-samples

Sample apps and code written for Google Cloud in the Go programming language.
Go
4,284
star
7

professional-services

Common solutions and tools developed by Google Cloud's Professional Services team. This repository and its contents are not an officially supported Google product.
Python
2,825
star
8

nodejs-docs-samples

Node.js samples for Google Cloud Platform products.
JavaScript
2,807
star
9

tensorflow-without-a-phd

A crash course in six episodes for software developers who want to become machine learning practitioners.
Jupyter Notebook
2,772
star
10

gcsfuse

A user-space file system for interacting with Google Cloud Storage
Go
2,046
star
11

community

Java
1,919
star
12

PerfKitBenchmarker

PerfKit Benchmarker (PKB) contains a set of benchmarks to measure and compare cloud offerings. The benchmarks use default settings to reflect what most users will see. PerfKit Benchmarker is licensed under the Apache 2 license terms. Please make sure to read, understand and agree to the terms of the LICENSE and CONTRIBUTING files before proceeding.
Python
1,885
star
13

asl-ml-immersion

This repos contains notebooks for the Advanced Solutions Lab: ML Immersion
Jupyter Notebook
1,799
star
14

vertex-ai-samples

Notebooks, code samples, sample apps, and other resources that demonstrate how to use, develop and manage machine learning and generative AI workflows using Google Cloud Vertex AI.
Jupyter Notebook
1,659
star
15

java-docs-samples

Java and Kotlin Code samples used on cloud.google.com
Java
1,610
star
16

ml-design-patterns

Source code accompanying O'Reilly book: Machine Learning Design Patterns
Jupyter Notebook
1,600
star
17

continuous-deployment-on-kubernetes

Get up and running with Jenkins on Google Kubernetes Engine
Shell
1,582
star
18

cloudml-samples

Cloud ML Engine repo. Please visit the new Vertex AI samples repo at https://github.com/GoogleCloudPlatform/vertex-ai-samples
Python
1,516
star
19

cloud-foundation-fabric

End-to-end modular samples and landing zones toolkit for Terraform on GCP.
HCL
1,509
star
20

cloud-builders

Builder images and examples commonly used for Google Cloud Build
Go
1,374
star
21

cloud-sql-proxy

A utility for connecting securely to your Cloud SQL instances
Go
1,263
star
22

cloud-builders-community

Community-contributed images for Google Cloud Build
Go
1,258
star
23

berglas

A tool for managing secrets on Google Cloud
Go
1,236
star
24

data-science-on-gcp

Source code accompanying book: Data Science on the Google Cloud Platform, Valliappa Lakshmanan, O'Reilly 2017
Jupyter Notebook
1,230
star
25

kubernetes-engine-samples

Sample applications for Google Kubernetes Engine (GKE)
HCL
1,228
star
26

functions-framework-nodejs

FaaS (Function as a service) framework for writing portable Node.js functions
TypeScript
1,162
star
27

DataflowTemplates

Cloud Dataflow Google-provided templates for solving in-Cloud data tasks
Java
1,135
star
28

bigquery-utils

Useful scripts, udfs, views, and other utilities for migration and data warehouse operations in BigQuery.
Java
1,117
star
29

cloud-vision

Sample code for Google Cloud Vision
Python
1,097
star
30

bank-of-anthos

Retail banking sample application showcasing Kubernetes and Google Cloud
Java
994
star
31

buildpacks

Builders and buildpacks designed to run on Google Cloud's container platforms
Go
982
star
32

php-docs-samples

A collection of samples that demonstrate how to call Google Cloud services from PHP.
PHP
961
star
33

cloud-foundation-toolkit

The Cloud Foundation toolkit provides GCP best practices as code.
Go
958
star
34

deploymentmanager-samples

Deployment Manager samples and templates.
Jinja
938
star
35

flask-talisman

HTTP security headers for Flask
Python
896
star
36

k8s-config-connector

GCP Config Connector, a Kubernetes add-on for managing GCP resources
Go
891
star
37

gsutil

A command line tool for interacting with cloud storage services.
Python
874
star
38

DataflowJavaSDK

Google Cloud Dataflow provides a simple, powerful model for building both batch and streaming parallel data processing pipelines.
857
star
39

nodejs-getting-started

A tutorial for creating a complete application using Node.js on Google Cloud Platform
JavaScript
806
star
40

magic-modules

Add Google Cloud Platform support to Terraform
Go
804
star
41

gcr-cleaner

Delete untagged image refs in Google Container Registry or Artifact Registry
Go
802
star
42

keras-idiomatic-programmer

Books, Presentations, Workshops, Notebook Labs, and Model Zoo for Software Engineers and Data Scientists wanting to learn the TF.Keras Machine Learning framework
Jupyter Notebook
797
star
43

metacontroller

Lightweight Kubernetes controllers as a service
Go
790
star
44

awesome-google-cloud

A curated list of awesome stuff for Google Cloud.
777
star
45

mlops-on-gcp

Jupyter Notebook
773
star
46

getting-started-python

Code samples for using Python on Google Cloud Platform
Python
756
star
47

dotnet-docs-samples

.NET code samples used on https://cloud.google.com
C#
736
star
48

click-to-deploy

Source for Google Click to Deploy solutions listed on Google Cloud Marketplace.
Python
729
star
49

iap-desktop

IAP Desktop is a Windows application that provides zero-trust Remote Desktop and SSH access to Linux and Windows VMs on Google Cloud.
C#
708
star
50

cloud-sdk-docker

Google Cloud CLI Docker Image - Docker Image containing the gcloud CLI and its bundled components.
Dockerfile
697
star
51

tf-estimator-tutorials

This repository includes tutorials on how to use the TensorFlow estimator APIs to perform various ML tasks, in a systematic and standardised way
Jupyter Notebook
671
star
52

functions-framework-python

FaaS (Function as a service) framework for writing portable Python functions
Python
670
star
53

flink-on-k8s-operator

[DEPRECATED] Kubernetes operator for managing the lifecycle of Apache Flink and Beam applications.
Go
657
star
54

terraform-google-examples

Collection of examples for using Terraform with Google Cloud Platform.
HCL
573
star
55

functions-framework-dart

FaaS (Function as a service) framework for writing portable Dart functions
Dart
535
star
56

cloud-run-button

Let anyone deploy your GitHub repos to Google Cloud Run with a single click
Go
527
star
57

bigquery-oreilly-book

Source code accompanying: BigQuery: The Definitive Guide by Lakshmanan & Tigani to be published by O'Reilly Media
Jupyter Notebook
523
star
58

govanityurls

Use a custom domain in your Go import path
Go
518
star
59

ml-on-gcp

Machine Learning on Google Cloud Platform
Python
484
star
60

practical-ml-vision-book

Jupyter Notebook
482
star
61

getting-started-java

Java
478
star
62

ipython-soccer-predictions

Sample iPython notebook with soccer predictions
Jupyter Notebook
473
star
63

monitoring-dashboard-samples

Google Cloud Monitoring Dashboard Samples
TypeScript
471
star
64

covid-19-open-data

Datasets of daily time-series data related to COVID-19 for over 20,000 distinct locations around the world.
Python
471
star
65

ai-platform-samples

Official Repo for Google Cloud AI Platform. Find samples for Vertex AI, Google Cloud's new unified ML platform at: https://github.com/GoogleCloudPlatform/vertex-ai-samples
Jupyter Notebook
457
star
66

hackathon-toolkit

GCP Hackathon Toolkit
HTML
440
star
67

gradle-appengine-templates

Freemarker based templates that build with the gradle-appengine-plugin
439
star
68

distributed-load-testing-using-kubernetes

Distributed load testing using Kubernetes on Google Container Engine
Smarty
438
star
69

terraform-validator

Terraform Validator is not an officially supported Google product; it is a library for conversion of Terraform plan data to CAI Assets. If you have been using terraform-validator directly in the past, we recommend migrating to `gcloud beta terraform vet`.
Go
437
star
70

cloud-code-vscode

Cloud Code for Visual Studio Code: Issues, Documentation and more
416
star
71

nodejs-docker

The Node.js Docker image used by Google App Engine Flexible.
TypeScript
407
star
72

cloud-ops-sandbox

Cloud Operations Sandbox is an open source collection of tools that helps practitioners to learn O11y and R9y practices from Google and apply them using Cloud Operations suite of tools.
HCL
405
star
73

professional-services-data-validator

Utility to compare data between homogeneous or heterogeneous environments to ensure source and target tables match
Python
403
star
74

k8s-stackdriver

Go
390
star
75

cloud-code-samples

Code templates to make working with Kubernetes feel like editing and debugging local code.
Java
387
star
76

healthcare

Python
374
star
77

require-so-slow

`require`s taking too much time? Profile 'em.
TypeScript
373
star
78

functions-framework-go

FaaS (Function as a service) framework for writing portable Go functions
Go
373
star
79

k8s-multicluster-ingress

kubemci: Command line tool to configure L7 load balancers using multiple kubernetes clusters
Go
372
star
80

compute-image-packages

Packages for Google Compute Engine Linux images.
Python
370
star
81

android-docs-samples

Java
365
star
82

stackdriver-errors-js

Client-side JavaScript exception reporting library for Cloud Error Reporting
JavaScript
358
star
83

applied-ai-engineering-samples

This repository compiles code samples and notebooks demonstrating how to use Generative AI on Google Cloud Vertex AI.
Jupyter Notebook
344
star
84

mlops-with-vertex-ai

An end-to-end example of MLOps on Google Cloud using TensorFlow, TFX, and Vertex AI
Jupyter Notebook
343
star
85

google-cloud-iot-arduino

Google Cloud IOT Example on ESP8266
C++
340
star
86

istio-samples

Istio demos and sample applications for GCP
Shell
331
star
87

ios-docs-samples

iOS samples that demonstrate APIs and services of Google Cloud Platform.
Swift
325
star
88

cloud-code-intellij

Plugin to support the Google Cloud Platform in IntelliJ IDEA - Docs and Issues Repository
319
star
89

security-analytics

Community Security Analytics provides a set of community-driven audit & threat queries for Google Cloud
Python
315
star
90

gke-networking-recipes

Shell
307
star
91

gcping

The source for the CLI and web app at gcping.com
Go
303
star
92

solutions-terraform-cloudbuild-gitops

HCL
301
star
93

spring-cloud-gcp

New home for Spring Cloud GCP development starting with version 2.0.
Java
299
star
94

airflow-operator

Kubernetes custom controller and CRDs to managing Airflow
Go
296
star
95

genai-for-marketing

Showcasing Google Cloud's generative AI for marketing scenarios via application frontend, backend, and detailed, step-by-step guidance for setting up and utilizing generative AI tools, including examples of their use in crafting marketing materials like blog posts and social media content, nl2sql analysis, and campaign personalization.
Jupyter Notebook
296
star
96

elixir-samples

A collection of samples on using Elixir with Google Cloud Platform.
Elixir
291
star
97

gcpdiag

gcpdiag is a command-line diagnostics tool for GCP customers.
Python
288
star
98

kotlin-samples

Kotlin
285
star
99

compute-archlinux-image-builder

A tool to build a Arch Linux Image for GCE
Shell
284
star
100

datalab-samples

Jupyter Notebook
281
star