Spaces:
Running
Running
<!-- livebook:{"app_settings":{"access_type":"public","auto_shutdown_ms":5000,"multi_session":true,"output_type":"rich","show_source":true,"slug":"repository-inspector"}} --> | |
# Repository inspector | |
```elixir | |
Mix.install([ | |
{:kino, "~> 0.10.0"}, | |
{:bumblebee, "~> 0.4.1"} | |
]) | |
``` | |
## Info | |
```elixir | |
Kino.Markdown.new(""" | |
Runs checks against the given HuggingFace repository to verify whether Bumblebee | |
supports the given model and any supporting components. | |
Not all supporting components are necessary for the given model. For example, | |
most models use either a tokenizer or a featurizer, but not both. If any of the | |
component does not exist it is probably fine, however pay attention to more | |
specific error messages. | |
""") | |
``` | |
## Checks | |
```elixir | |
version = Application.spec(:bumblebee)[:vsn] | |
Kino.Markdown.new(""" | |
`bumblebee: #{version}` | |
""") | |
``` | |
```elixir | |
repo_input = Kino.Input.text("HuggingFace repo") | |
``` | |
```elixir | |
subdir_input = Kino.Input.text("Subdirectory (optional)") | |
``` | |
```elixir | |
repo = Kino.Input.read(repo_input) | |
subdir = Kino.Input.read(subdir_input) | |
if repo == "" do | |
Kino.interrupt!(:normal, "Enter repository.") | |
end | |
repo = | |
if subdir == "" do | |
{:hf, repo} | |
else | |
{:hf, repo, subdir: subdir} | |
end | |
repo_snippet = repo |> Macro.escape() |> Macro.to_string() | |
``` | |
```elixir | |
safe_apply = fn fun -> | |
try do | |
fun.() | |
rescue | |
error -> {:error, Exception.message(error)} | |
end | |
end | |
``` | |
```elixir | |
Kino.Markdown.new("### Model") | |
``` | |
````elixir | |
case safe_apply.(fn -> Bumblebee.load_spec(repo) end) do | |
{:ok, _spec} -> | |
Kino.Markdown.new(""" | |
π Model specification available. This means that **Bumblebee supports this model**. | |
```elixir | |
{:ok, model_info} = Bumblebee.load_model(#{repo_snippet}) | |
``` | |
""") | |
{:error, message} -> | |
Kino.Markdown.new(""" | |
π€·ββοΈ Failed to load, reason: #{message}. | |
""") | |
end | |
```` | |
```elixir | |
Kino.Markdown.new("### Tokenizer") | |
``` | |
````elixir | |
case safe_apply.(fn -> Bumblebee.load_tokenizer(repo) end) do | |
{:ok, _tokenizer} -> | |
Kino.Markdown.new(""" | |
π Tokenizer available. | |
```elixir | |
{:ok, tokenizer} = Bumblebee.load_tokenizer(#{repo_snippet}) | |
``` | |
""") | |
{:error, message} -> | |
Kino.Markdown.new(""" | |
π€·ββοΈ Failed to load, reason: #{message}. | |
""") | |
end | |
```` | |
```elixir | |
Kino.Markdown.new("### Featurizer") | |
``` | |
````elixir | |
case safe_apply.(fn -> Bumblebee.load_featurizer(repo) end) do | |
{:ok, _featurizer} -> | |
Kino.Markdown.new(""" | |
π Featurizer available. | |
```elixir | |
{:ok, featurizer} = Bumblebee.load_featurizer(#{repo_snippet}) | |
``` | |
""") | |
{:error, message} -> | |
Kino.Markdown.new(""" | |
π€·ββοΈ Failed to load, reason: #{message}. | |
""") | |
end | |
```` | |
```elixir | |
Kino.Markdown.new(""" | |
### Generation config | |
*Note: this check may give a false positive. Whether you want to load | |
a generation config, depends on the task you are performing.* | |
""") | |
``` | |
````elixir | |
default_config = Bumblebee.configure(Bumblebee.Text.GenerationConfig) | |
case safe_apply.(fn -> Bumblebee.load_generation_config(repo) end) do | |
{:ok, config} -> | |
# Generation attributes should be stored in generation_config.json, | |
# however old repos keep them as part of config.json. This means | |
# that generation config can always be loaded. | |
# | |
# We use a simple heuristic, if all attributes have their default | |
# value, it means there is effectively no generation config. | |
# However, a couple attributes, nameply :bos_token_id, :eos_token_id, | |
# :pad_token_id, may appear in config.json irrespectively of | |
# generation, which causes a false positive. | |
if config == default_config do | |
Kino.Markdown.new(""" | |
π€·ββοΈ Failed to load, reason: no generation config found in the given repository. | |
""") | |
else | |
Kino.Markdown.new(""" | |
π Generation config available. | |
```elixir | |
{:ok, generation_config} = Bumblebee.load_generation_config(#{repo_snippet}) | |
``` | |
""") | |
end | |
{:error, message} -> | |
Kino.Markdown.new(""" | |
π€·ββοΈ Failed to load, reason: #{message}. | |
""") | |
end | |
```` | |
```elixir | |
Kino.Markdown.new("### Scheduler") | |
``` | |
````elixir | |
case safe_apply.(fn -> Bumblebee.load_scheduler(repo) end) do | |
{:ok, _featurizer} -> | |
Kino.Markdown.new(""" | |
π Scheduler available. | |
```elixir | |
{:ok, scheduler} = Bumblebee.load_scheduler(#{repo_snippet}) | |
``` | |
""") | |
{:error, message} -> | |
Kino.Markdown.new(""" | |
π€·ββοΈ Failed to load, reason: #{message}. | |
""") | |
end | |
```` | |