BFloat16 не поддерживается в MPS (macOS)Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 BFloat16 не поддерживается в MPS (macOS)

Сообщение Anonymous »

Я получил доступ к модели на основе ламы на Huggingface под названием «LeoLM/leo-hessianai-7b-chat».
Я загрузил модель на свой Mac с устройством, установленным как «MPS». Загрузка прошла успешно, однако, когда я хочу протестировать модель, я получаю следующую ошибку:

Код: Выделить всё

TypeError: BFloat16 is not supported on MPS
Выше я вижу подсказку:

Код: Выделить всё

FP4 quantization state not initialized. Please call .cuda() or .to(device) on the LinearFP4 layer first.
Вот мой код:

Код: Выделить всё

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"])
Что мне нужно изменить, чтобы он заработал?

Подробнее здесь: https://stackoverflow.com/questions/773 ... -mps-macos
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Ошибка выполнения: серверная часть MPS поддерживается в MacOS 12.3+. Текущую версию ОС можно запросить с помощью `sw_ver
    Anonymous » » в форуме Python
    0 Ответы
    14 Просмотры
    Последнее сообщение Anonymous
  • Поддержка Python для BFloat16 в macOS
    Anonymous » » в форуме Python
    0 Ответы
    22 Просмотры
    Последнее сообщение Anonymous
  • Использование bfloat16 и tensorflow на графическом процессоре
    Anonymous » » в форуме Python
    0 Ответы
    31 Просмотры
    Последнее сообщение Anonymous
  • Сохраните bfloat16 в двоичном формате.
    Anonymous » » в форуме Python
    0 Ответы
    19 Просмотры
    Последнее сообщение Anonymous
  • Уменьшение памяти Tensorflow TPU v2/v3 bfloat16
    Anonymous » » в форуме Python
    0 Ответы
    28 Просмотры
    Последнее сообщение Anonymous

Вернуться в «Python»