

python --versioncd command.python -m venv gemma-env to create a new virtual environment named gemma-env.gemma-env\Scripts\activate — On macOS/Linux: source gemma-env/bin/activate(gemma-env) at the start — you're inside the environment.pip install transformers torch accelerate bitsandbytespip install nvidia-cublas-cu12
hf_xxxxxxxxxx.huggingface-cli login
download_gemma.py and add the following code:from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "google/gemma-4-it"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto"
)python download_gemma.py. The download is approximately 5–9 GB depending on the model variant selected.BitsAndBytesConfig as shown below:from transformers import BitsAndBytesConfig
import torch
quant_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.float16
)
model = AutoModelForCausalLM.from_pretrained(
model_id,
quantization_config=quant_config,
device_map="auto"
)
input_text = "Explain quantum computing in simple terms."
inputs = tokenizer(input_text, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=200)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))python your_script.py. Within a few seconds — or moments if you have a GPU — Gemma 4 will generate its response directly in your terminal. Congratulations, you're now running a state-of-the-art AI model locally!
ollama run gemma4pip install open-webui in your terminal after ensuring Ollama is already installed and running.open-webui serve and wait for the local server to initialise.http://localhost:3000 in your web browser to access the chat dashboard.BitsAndBytesConfig as shown in the earlier step.huggingface-cli login and paste a fresh token. Make sure you've accepted the Gemma 4 licence on the model page.device_map="cpu" with quantisation, or try Ollama which optimises CPU performance more aggressively.pip install transformers torch accelerate.