Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dynamo
Commits
0f4529e9
Commit
0f4529e9
authored
Mar 14, 2025
by
Ryan McCormick
Committed by
GitHub
Mar 14, 2025
Browse files
fix: Improve error handling for failed HF download (#160)
parent
6a93d2c7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
4 deletions
+52
-4
launch/dynamo-run/src/hub.rs
launch/dynamo-run/src/hub.rs
+52
-4
No files found.
launch/dynamo-run/src/hub.rs
View file @
0f4529e9
...
...
@@ -22,16 +22,59 @@ const IGNORED: [&str; 3] = [".gitattributes", "LICENSE", "README.md"];
/// Returns the directory it is in
pub
async
fn
from_hf
(
name
:
&
Path
)
->
anyhow
::
Result
<
PathBuf
>
{
let
api
=
ApiBuilder
::
new
()
.with_progress
(
true
)
.build
()
?
;
let
model_name
=
name
.display
()
.to_string
();
let
repo
=
api
.model
(
model_name
.clone
());
let
info
=
match
repo
.info
()
.await
{
Ok
(
info
)
=>
info
,
Err
(
e
)
=>
{
return
Err
(
anyhow
::
anyhow!
(
"Failed to fetch model '{}' from HuggingFace: {}. Is this a valid HuggingFace ID?"
,
model_name
,
e
));
}
};
if
info
.siblings
.is_empty
()
{
return
Err
(
anyhow
::
anyhow!
(
"Model '{}' exists but contains no downloadable files."
,
model_name
));
}
let
repo
=
api
.model
(
name
.display
()
.to_string
());
let
info
=
repo
.info
()
.await
?
;
let
mut
p
=
PathBuf
::
new
();
let
mut
files_downloaded
=
false
;
for
sib
in
info
.siblings
{
if
IGNORED
.contains
(
&
sib
.rfilename
.as_str
())
||
is_image
(
&
sib
.rfilename
)
{
continue
;
}
p
=
repo
.get
(
&
sib
.rfilename
)
.await
?
;
match
repo
.get
(
&
sib
.rfilename
)
.await
{
Ok
(
path
)
=>
{
p
=
path
;
files_downloaded
=
true
;
}
Err
(
e
)
=>
{
return
Err
(
anyhow
::
anyhow!
(
"Failed to download file '{}' from model '{}': {}"
,
sib
.rfilename
,
model_name
,
e
));
}
}
}
if
!
files_downloaded
{
return
Err
(
anyhow
::
anyhow!
(
"No valid files found for model '{}'."
,
model_name
));
}
match
p
.parent
()
{
Some
(
p
)
=>
Ok
(
p
.to_path_buf
()),
None
=>
Err
(
anyhow
::
anyhow!
(
"Invalid HF cache path: {}"
,
p
.display
())),
...
...
@@ -39,5 +82,10 @@ pub async fn from_hf(name: &Path) -> anyhow::Result<PathBuf> {
}
fn
is_image
(
s
:
&
str
)
->
bool
{
s
.ends_with
(
".png"
)
||
s
.ends_with
(
"PNG"
)
||
s
.ends_with
(
".jpg"
)
||
s
.ends_with
(
"JPG"
)
s
.ends_with
(
".png"
)
||
s
.ends_with
(
"PNG"
)
||
s
.ends_with
(
".jpg"
)
||
s
.ends_with
(
"JPG"
)
||
s
.ends_with
(
".jpeg"
)
||
s
.ends_with
(
"JPEG"
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment