扩展磁盘-GCP VM
[TOC]
Weeks ago, I created a GCP VM for the VPN and Jupyter notebook server, however I used the minimum spec in order to save the cost. The disk was only 10G, which could not meet the requirements of Pytorch installation, so I got to extend the capacity of my vm disk to which is 20G in my case.
The Pytorch is required in transformers.GPT2LMHeadModel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
201 # Import the necessary libraries
2 from transformers import GPT2Tokenizer, GPT2LMHeadModel
3
4 # Load the pre-trained GPT-2 tokenizer and model
5 tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
6 model = GPT2LMHeadModel.from_pretrained('gpt2')
7
8 # Set the model to evaluation mode
9 model.eval()
10
11 # Define a prompt for the model to complete
12 prompt = input("You: ")
13
14 # Tokenize the prompt and generate text
15 input_ids = tokenizer.encode(prompt, return_tensors='pt')
16 output = model.generate(input_ids, max_length=50, do_sample=True)
17
18 # Decode the generated text and print it to the console
19 generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
20 print("AI: " + generated_text)
Install Pytorch
Installation
Refer to PyTorch
1 | |
By default, pip will download all the packages into memory instead of the disk for installation, use
--no-cache-dirto avoid downloading them into memory.
VERIFICATION
To ensure that PyTorch was installed correctly, we can verify the installation by running sample PyTorch code. Here we will construct a randomly initialized tensor.
1 | |
The output should be something similar to:
1 | |
Extend disk of GCP VM
扩展磁盘-GCP VM
https://blog.excelsre.com/2023/06/11/kuo-zhan-ci-pan-gcp-vm/