darnahsan

darnahsan

Using Phi3.5 wih Bumblebee: (ArgumentError) could not match the class name "Phi3ForCausalLM" to any of the supported models

I am trying to see how I can use different HF models with Bumblebee. I am trying to load microsoft/Phi-3.5-mini-instruct

{:ok, microsoft} = Bumblebee.load_model({:hf, "microsoft/Phi-3.5-mini-instruct"})

and getting following error.

** (ArgumentError) could not match the class name "Phi3ForCausalLM" to any of the supported models, please specify the :module and :architecture options
    (bumblebee 0.5.3) lib/bumblebee.ex:409: Bumblebee.do_load_spec/4
    (bumblebee 0.5.3) lib/bumblebee.ex:578: Bumblebee.maybe_load_model_spec/3
    (bumblebee 0.5.3) lib/bumblebee.ex:566: Bumblebee.load_model/2
    #cell:etc7eozxbver4bzi:1: (file

but the lib/bumblebee.ex list Phi3ForCausalLM. Shouldn’t it be able to load this as module and architecture are listed there ? Am I missing something as just started exploring this space

https://github.com/elixir-nx/bumblebee/blob/main/lib/bumblebee.ex#L178

Marked As Solved

jonatanklosko

jonatanklosko

Creator of Livebook

Oh, you mean the model repeats words, not that it gets stuck without output. So that is not a bug, it’s just how the model behaves under the given configuration.

There are several factors that determine the model output. First of all, sometimes the model has a separate “base” and “instruct” checkpoints. Base models are trained on a bunch of text to get “text understanding”, and instruct models are further fine-tuned on conversations and tasks, to make them more usable in a chat-like interaction. For example, there is HuggingFaceTB/SmolLM-1.7B and HuggingFaceTB/SmolLM-1.7B-instruct, you probably want to use the latter.

Next, you want to make sure you use a prompt relevant for the given model. Instruct checkpoints usually have a certain template for specifying the conversation history. With the transformers Python library you can specify a template on the tokenizer, however it use a Python-specific template, so we can’t reliably load it. However, you can find the template by looking for “chat_template” in tokenizer_config.json in the given repo. Sometimes the template is also present in the model readme. Continuing with SmolLM instruct, the template is here. So here is the prompt with template:

prompt = """
<|im_start|>user
Complete the paragraph: our solar system is<|im_end|>\
<|im_start|>assistant
"""

It results in a much better result.

Finally you can make the output non-deterministic (and more creative) by using a sampling strategy for the generation, such as this:

generation_config =
  Bumblebee.configure(generation_config,
    strategy: %{type: :multinomial_sampling, top_p: 0.6}
  )

(Sidenote: there is also :no_repeat_ngram_length to explicitly avoid repetitions, however it is a trade-off, because sometimes there are longer pharses, city names, etc, and preventing the model from reusing them worsens the usability)

Also Liked

jonatanklosko

jonatanklosko

Creator of Livebook

@darnahsan I fixed the rope scaling, so you should be able to get pass that error on Bumblebee main : )

darnahsan

darnahsan

Bumblebee 101

Mix.install([
  {:bumblebee, [github: "elixir-nx/bumblebee", override: true]},
  {:nx, "~> 0.8.0", [override: true]},
  {:exla, "~> 0.8.0", [override: true]},
  {:kino, "~> 0.14.0", [override: true]},
  {:kino_bumblebee, [github: "livebook-dev/kino_bumblebee", override: true]},
  {:kino_db, "~> 0.2.12"}
])

Nx.global_default_backend({EXLA.Backend, client: :host})

Untitled

hf_token = System.fetch_env!("LB_HF_TOKEN")
{:ok, bert} = Bumblebee.load_model({:hf, "google-bert/bert-base-uncased"})
{:ok, tokenizer} = Bumblebee.load_tokenizer({:hf, "google-bert/bert-base-uncased"})

serving = Bumblebee.Text.fill_mask(bert, tokenizer)

text_input = Kino.Input.text("Sentence with mask", default: "The capital of [MASK] is Paris.")
text = Kino.Input.read(text_input)

Nx.Serving.run(serving, text)
phi3_5 = {:hf, "microsoft/Phi-3.5-mini-instruct"}
t5_flant = {:hf, "google/flan-t5-large"}
smollm = {:hf, "HuggingFaceTB/SmolLM-1.7B"}
llama_minitron = {:hf, "nvidia/Llama-3.1-Minitron-4B-Width-Base"}
repo = phi3_5
{:ok, model} = Bumblebee.load_model(repo)
{:ok, tokenizer} = Bumblebee.load_tokenizer(repo)
{:ok, generation_config} = Bumblebee.load_generation_config(repo)
generation_config = Bumblebee.configure(generation_config, max_new_tokens: 256)
serving = Bumblebee.Text.generation(model, tokenizer, generation_config,
        compile: [batch_size: 1, sequence_length: 256],
        stream: true,
        defn_options: [compiler: EXLA]
)
Kino.start_child({Nx.Serving, name: Model, serving: serving})
prompt = "Complete the paragraph: our solar system is"

Nx.Serving.batched_run(Model, prompt) |> Enum.each(&IO.write/1)
jonatanklosko

jonatanklosko

Creator of Livebook

It was added after the last release, so try bumblebee main : )

Where Next?

Popular in Questions Top

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New

We're in Beta

About us Mission Statement