jonatanklosko commited on
Commit
a9b9410
β€’
1 Parent(s): 808e59a

Add repository inspector

Browse files
public-apps/repository-inspector.livemd ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- livebook:{"app_settings":{"access_type":"public","auto_shutdown_ms":5000,"multi_session":true,"output_type":"rich","show_source":true,"slug":"repository-inspector"}} -->
2
+
3
+ # Repository inspector
4
+
5
+ ```elixir
6
+ Mix.install([
7
+ {:kino, "~> 0.10.0"},
8
+ {:bumblebee, "~> 0.4.1"}
9
+ ])
10
+ ```
11
+
12
+ ## Info
13
+
14
+ ```elixir
15
+ Kino.Markdown.new("""
16
+ Runs checks against the given HuggingFace repository to verify whether Bumblebee
17
+ supports the given model and any supporting components.
18
+
19
+ Not all supporting components are necessary for the given model. For example,
20
+ most models use either a tokenizer or a featurizer, but not both. If any of the
21
+ component does not exist it is probably fine, however pay attention to more
22
+ specific error messages.
23
+ """)
24
+ ```
25
+
26
+ ## Checks
27
+
28
+ ```elixir
29
+ version = Application.spec(:bumblebee)[:vsn]
30
+
31
+ Kino.Markdown.new("""
32
+ `bumblebee: #{version}`
33
+ """)
34
+ ```
35
+
36
+ ```elixir
37
+ repo_input = Kino.Input.text("HuggingFace repo")
38
+ ```
39
+
40
+ ```elixir
41
+ subdir_input = Kino.Input.text("Subdirectory (optional)")
42
+ ```
43
+
44
+ ```elixir
45
+ repo = Kino.Input.read(repo_input)
46
+ subdir = Kino.Input.read(subdir_input)
47
+
48
+ if repo == "" do
49
+ Kino.interrupt!(:normal, "Enter repository.")
50
+ end
51
+
52
+ repo =
53
+ if subdir == "" do
54
+ {:hf, repo}
55
+ else
56
+ {:hf, repo, subdir: subdir}
57
+ end
58
+
59
+ repo_snippet = repo |> Macro.escape() |> Macro.to_string()
60
+ ```
61
+
62
+ ```elixir
63
+ safe_apply = fn fun ->
64
+ try do
65
+ fun.()
66
+ rescue
67
+ error -> {:error, Exception.message(error)}
68
+ end
69
+ end
70
+ ```
71
+
72
+ ```elixir
73
+ Kino.Markdown.new("### Model")
74
+ ```
75
+
76
+ ````elixir
77
+ case safe_apply.(fn -> Bumblebee.load_spec(repo) end) do
78
+ {:ok, _spec} ->
79
+ Kino.Markdown.new("""
80
+ πŸš€ Model specification available. This means that **Bumblebee supports this model**.
81
+
82
+ ```elixir
83
+ {:ok, model_info} = Bumblebee.load_model(#{repo_snippet})
84
+ ```
85
+ """)
86
+
87
+ {:error, message} ->
88
+ Kino.Markdown.new("""
89
+ πŸ€·β€β™‚οΈ Failed to load, reason: #{message}.
90
+ """)
91
+ end
92
+ ````
93
+
94
+ ```elixir
95
+ Kino.Markdown.new("### Tokenizer")
96
+ ```
97
+
98
+ ````elixir
99
+ case safe_apply.(fn -> Bumblebee.load_tokenizer(repo) end) do
100
+ {:ok, _tokenizer} ->
101
+ Kino.Markdown.new("""
102
+ πŸš€ Tokenizer available.
103
+
104
+ ```elixir
105
+ {:ok, tokenizer} = Bumblebee.load_tokenizer(#{repo_snippet})
106
+ ```
107
+ """)
108
+
109
+ {:error, message} ->
110
+ Kino.Markdown.new("""
111
+ πŸ€·β€β™‚οΈ Failed to load, reason: #{message}.
112
+ """)
113
+ end
114
+ ````
115
+
116
+ ```elixir
117
+ Kino.Markdown.new("### Featurizer")
118
+ ```
119
+
120
+ ````elixir
121
+ case safe_apply.(fn -> Bumblebee.load_featurizer(repo) end) do
122
+ {:ok, _featurizer} ->
123
+ Kino.Markdown.new("""
124
+ πŸš€ Featurizer available.
125
+
126
+ ```elixir
127
+ {:ok, featurizer} = Bumblebee.load_featurizer(#{repo_snippet})
128
+ ```
129
+ """)
130
+
131
+ {:error, message} ->
132
+ Kino.Markdown.new("""
133
+ πŸ€·β€β™‚οΈ Failed to load, reason: #{message}.
134
+ """)
135
+ end
136
+ ````
137
+
138
+ ```elixir
139
+ Kino.Markdown.new("""
140
+ ### Generation config
141
+
142
+ *Note: this check may give a false positive. Whether you want to load
143
+ a generation config, depends on the task you are performing.*
144
+ """)
145
+ ```
146
+
147
+ ````elixir
148
+ default_config = Bumblebee.configure(Bumblebee.Text.GenerationConfig)
149
+
150
+ case safe_apply.(fn -> Bumblebee.load_generation_config(repo) end) do
151
+ {:ok, config} ->
152
+ # Generation attributes should be stored in generation_config.json,
153
+ # however old repos keep them as part of config.json. This means
154
+ # that generation config can always be loaded.
155
+ #
156
+ # We use a simple heuristic, if all attributes have their default
157
+ # value, it means there is effectively no generation config.
158
+ # However, a couple attributes, nameply :bos_token_id, :eos_token_id,
159
+ # :pad_token_id, may appear in config.json irrespectively of
160
+ # generation, which causes a false positive.
161
+
162
+ if config == default_config do
163
+ Kino.Markdown.new("""
164
+ πŸ€·β€β™‚οΈ Failed to load, reason: no generation config found in the given repository.
165
+ """)
166
+ else
167
+ Kino.Markdown.new("""
168
+ πŸš€ Generation config available.
169
+
170
+ ```elixir
171
+ {:ok, generation_config} = Bumblebee.load_generation_config(#{repo_snippet})
172
+ ```
173
+ """)
174
+ end
175
+
176
+ {:error, message} ->
177
+ Kino.Markdown.new("""
178
+ πŸ€·β€β™‚οΈ Failed to load, reason: #{message}.
179
+ """)
180
+ end
181
+ ````
182
+
183
+ ```elixir
184
+ Kino.Markdown.new("### Scheduler")
185
+ ```
186
+
187
+ ````elixir
188
+ case safe_apply.(fn -> Bumblebee.load_scheduler(repo) end) do
189
+ {:ok, _featurizer} ->
190
+ Kino.Markdown.new("""
191
+ πŸš€ Scheduler available.
192
+
193
+ ```elixir
194
+ {:ok, scheduler} = Bumblebee.load_scheduler(#{repo_snippet})
195
+ ```
196
+ """)
197
+
198
+ {:error, message} ->
199
+ Kino.Markdown.new("""
200
+ πŸ€·β€β™‚οΈ Failed to load, reason: #{message}.
201
+ """)
202
+ end
203
+ ````