Я получил доступ к модели на основе ламы на Huggingface под названием «LeoLM/leo-hessianai-7b-chat».
Я загрузил модель на свой Mac с устройством, установленным как «MPS». Загрузка прошла успешно, однако, когда я хочу протестировать модель, я получаю следующую ошибку:
from torch import cuda, bfloat16
import transformers
device = torch.device("mps")
model_id = 'LeoLM/leo-hessianai-7b-chat'
#device = f'cuda:{cuda.current_device()}' if cuda.is_available() else 'cpu'
# set quantization configuration to load large model with less GPU memory
# this requires the `bitsandbytes` library
bnb_config = transformers.BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type='nf4',
bnb_4bit_use_double_quant=True,
bnb_4bit_compute_dtype=bfloat16
)
# begin initializing HF items, need auth token for these
hf_auth = 'HF_KEY'
model_config = transformers.AutoConfig.from_pretrained(
model_id,
use_auth_token=hf_auth
)
model = transformers.AutoModelForCausalLM.from_pretrained(
model_id,
trust_remote_code=False, # True for flash attention
config=model_config,
quantization_config=bnb_config,
device_map='auto',
use_auth_token=hf_auth
)
model.eval()
print(f"Model loaded on {device}")
tokenizer = transformers.AutoTokenizer.from_pretrained(
model_id,
use_auth_token=hf_auth
)
generate_text = transformers.pipeline(
model=model, tokenizer=tokenizer,
return_full_text=True, # langchain expects the full text
task='text-generation',
# we pass model parameters here too
temperature=0.0, # 'randomness' of outputs, 0.0 is the min and 1.0 the max
max_new_tokens=512, # mex number of tokens to generate in the output
repetition_penalty=1.1 # without this output begins repeating
)
res = generate_text("Explain the difference between a country and a continent.")
print(res[0]["generated_text"])
Я получил доступ к модели на основе ламы на Huggingface под названием «LeoLM/leo-hessianai-7b-chat». Я загрузил модель на свой Mac с устройством, установленным как «MPS». Загрузка прошла успешно, однако, когда я хочу протестировать модель, я получаю следующую ошибку: [code]TypeError: BFloat16 is not supported on MPS [/code] Выше я вижу подсказку: [code]FP4 quantization state not initialized. Please call .cuda() or .to(device) on the LinearFP4 layer first. [/code] Вот мой код: [code]from torch import cuda, bfloat16 import transformers
device = torch.device("mps")
model_id = 'LeoLM/leo-hessianai-7b-chat'
#device = f'cuda:{cuda.current_device()}' if cuda.is_available() else 'cpu'
# set quantization configuration to load large model with less GPU memory # this requires the `bitsandbytes` library bnb_config = transformers.BitsAndBytesConfig( load_in_4bit=True, bnb_4bit_quant_type='nf4', bnb_4bit_use_double_quant=True, bnb_4bit_compute_dtype=bfloat16 )
# begin initializing HF items, need auth token for these hf_auth = 'HF_KEY' model_config = transformers.AutoConfig.from_pretrained( model_id, use_auth_token=hf_auth )
model = transformers.AutoModelForCausalLM.from_pretrained( model_id, trust_remote_code=False, # True for flash attention config=model_config, quantization_config=bnb_config, device_map='auto', use_auth_token=hf_auth ) model.eval() print(f"Model loaded on {device}")
generate_text = transformers.pipeline( model=model, tokenizer=tokenizer, return_full_text=True, # langchain expects the full text task='text-generation', # we pass model parameters here too temperature=0.0, # 'randomness' of outputs, 0.0 is the min and 1.0 the max max_new_tokens=512, # mex number of tokens to generate in the output repetition_penalty=1.1 # without this output begins repeating )
res = generate_text("Explain the difference between a country and a continent.") print(res[0]["generated_text"]) [/code] Что мне нужно изменить, чтобы он заработал?
Поскольку поддержка графического процессора Pytorch для Apple Silicon была только что выпущена, я попытался установить PyTorch, выполнив действия, описанные по следующей ссылке. На данный момент доступна только ночная сборка, поэтому я установил ее....
Я пытаюсь использовать модель bigscience/bloom в macOS для завершения текста. Вот скрипт Python, который я использую:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
Каков идиоматический способ сохранения bfloat torch.tensor на диск в виде необработанного двоичного файла? Код ниже выдаст ошибку, поскольку numpy не поддерживает bfloat16.
import torch
import numpy as np
Моя модель слишком велика, чтобы получить партию >64 с обычными устройствами TPU v2. На сайте устранения неполадок упоминается, что в будущих версиях tensorflow будет поддержка bfloat16. Могут ли недавно поддерживаемые версии tf 1.9–1.12...