Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Official instructions: https://huggingface.co/docs/transformers/main/en/model_doc/bloom#transformers.BloomForCausalLM
- # Find help here: https://discuss.huggingface.co
- # Nice guide here: https://towardsdatascience.com/getting-started-with-bloom-9e3295459b65
- # python -m venv name
- # source name/bin/activate
- # pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cu117 # From https://pytorch.org/get-started/locally/
- # pip install transformers bitsandbytes accelerate
- # accelerate config
- # python
- import torch
- from transformers import BloomTokenizerFast, BloomForCausalLM
- tokenizer = BloomTokenizerFast.from_pretrained("bigscience/bloom-3b")
- model = BloomForCausalLM.from_pretrained("bigscience/bloom-3b", device_map="auto", load_in_8bit=True)
- prompt = "Dave picked up the baseball and"
- result_length = 200
- inputs = tokenizer(prompt, return_tensors="pt")
- device = torch.device("cuda:0")
- inputs2 = inputs.to(device)
- greedy = model.generate(inputs2["input_ids"],max_length=result_length)[0]
- beam = model.generate(inputs2["input_ids"],max_length=result_length, num_beams=2, no_repeat_ngram_size=2,early_stopping=True)[0]
- sampling = model.generate(inputs2["input_ids"],max_length=result_length, do_sample=True, top_k=50, top_p=0.9)[0]
- print(tokenizer.decode(greedy))
- print(tokenizer.decode(beam))
- print(tokenizer.decode(sampling))
Advertisement
Add Comment
Please, Sign In to add comment