# Code Server Use Case

**Step 1**: Create a GPU Container using Code Server &#x20;

<figure><img src="/files/WE3VYKbe6N3ASYR8wWtE" alt=""><figcaption></figcaption></figure>

**Step 2**: install python3, pip&#x20;

```
sudo apt update && sudo apt install -y python3 python3-pip python3-venv git 
```

**Step 3**: using virtual environment to install required python packages and run training code&#x20;

```
python3 -m venv ~/venv  
source ~/venv/bin/activate 
```

**Step 4**: Install required python packages&#x20;

```
pip install --upgrade pip  
pip install torch torchvision torchaudio scikit-learn scipy --index-url 
https://download.pytorch.org/whl/cu121
  
pip install datasets evaluate accelerate
```

&#x20;

**Step 5**: Clone Hugging Face transformers from Github&#x20;

```
 cd /workspace    
 git clone https://github.com/huggingface/transformers.git  
 pip install –e . 
```

<figure><img src="/files/JmX4J7StvpQ1t9FpMIS9" alt=""><figcaption></figcaption></figure>

**Step 6:** Install python package

```
pip install scikit-learn scipy 
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 
```

**Step 7**: Finetune BERT on GLUE MRPC. Your output will be stored at /tmp/bert-finetuned&#x20;

In this step, you will fine-tune the pre-trained BERT model on the Microsoft Research Paraphrase Corpus (MRPC) task from the GLUE benchmark. This means the model will learn to classify whether two sentences are paraphrases (have the same meaning) or not.&#x20;

```
cd /workspace/transformers/examples/pytorch/text-classification 
python3 run_glue.py  
--model_name_or_path bert-base-uncased  
--task_name mrpc  
--do_train  
--do_eval  
--per_device_train_batch_size 16  
--learning_rate 2e-5  
--num_train_epochs 3  
--output_dir /tmp/bert-finetuned  
--overwrite_output_dir 
```

<figure><img src="/files/gmepE1vEIdHN2npe30xj" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/cwo79crF2NyS0eNcSRok" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/onsz39NFW9h94B6WVoFy" alt=""><figcaption></figcaption></figure>

**Step 7**: Create a file contains test script called test.py. Insert the code below.&#x20;

```
from transformers import BertTokenizer, BertForSequenceClassification 
import torch 
 
# Load fine-tuned model and tokenizer 
model_path = "/tmp/bert-finetuned" 
model = BertForSequenceClassification.from_pretrained(model_path) 
tokenizer = BertTokenizer.from_pretrained("bert-base-uncased") 
 
# Move model to GPU 
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") 
model.to(device) 
model.eval() 
 
# Prepare test sentence 
# sentence = "This is a demo for code server GPU Container!" 
# inputs = tokenizer(sentence, return_tensors="pt").to(device) 
sentence1 = "This is a great example!" 
sentence2 = "This is a demo for code server GPU Container!" 
 
inputs = tokenizer(sentence1, sentence2, return_tensors="pt").to(device) 
 
# Run inference 
with torch.no_grad(): 
outputs = model(**inputs) 
logits = outputs.logits 
predicted_class = torch.argmax(logits, dim=1).item() 
 
# Map class to label (MRPC uses 0/1) 
label_map = {0: "not paraphrase", 1: "paraphrase"} 
print(f"Sentence: {sentence1}") 
print(f"Sentence: {sentence2}") 
print(f"Predicted Class: {predicted_class} ({label_map[predicted_class]})")  
```

&#x20;

**Step 8**: Run test.py to test the finetuned model&#x20;

```
python3 test.py 
```

<figure><img src="/files/KzOxM8xNhwkENqJLmRco" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ai-docs.fptcloud.com/fpt-gpu-cloud/gpu-container/use-cases/code-server-use-case.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
