Skip to content

Add functionality to resolve external weights from safetensors and the webnn-graph weights file.#12

Merged
mtavenrath merged 6 commits intomainfrom
resolve_weights
Apr 24, 2026
Merged

Add functionality to resolve external weights from safetensors and the webnn-graph weights file.#12
mtavenrath merged 6 commits intomainfrom
resolve_weights

Conversation

@mtavenrath
Copy link
Copy Markdown
Contributor

This change adds support to resolve weight references into inline weights from .safetensors and wenn weight files.

Since .safetensor files might contain weights in a different format than the converted webnn graph support for weight conversion. Currently only the conversion from bfloat16 to float32 is implemented.

@tarekziade
Copy link
Copy Markdown
Collaborator

Nice! besides the existing tests, would it be possible to have a safetensor sample in in /examples we can load in an e2e test. It will also be useful to boostrap support in other libs in the project

Copy link
Copy Markdown
Collaborator

@tarekziade tarekziade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TY!

Comment thread src/external_weights.rs Outdated
fn out_of_bounds_manifest_errors() {
let temp_dir = TempDir::new().unwrap();
let graph_path = temp_dir.path().join("model.json");
let manifest_path = temp_dir.path().join("manifest.json");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you put all default filenames at the top of the module as CONSTs?

Comment thread src/external_weights.rs Outdated
.and_then(|s| s.to_str())
.unwrap_or_default();
[
graph_path.with_file_name("model.safetensors"),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same remark, lets collect all defaults at the top to surface our naming conventions/standards in a single spot

@mtavenrath
Copy link
Copy Markdown
Contributor Author

Nice! besides the existing tests, would it be possible to have a safetensor sample in in /examples we can load in an e2e test. It will also be useful to boostrap support in other libs in the project

I have changes ready to use this function in pywebnn and rustnn. Examples will follow soon.

@mtavenrath mtavenrath changed the title Add support for weight inlining Add functionality to resolve external weights from safetensors and the webnn-graph weights file. Apr 24, 2026
@mtavenrath mtavenrath merged commit 4dd1ec6 into main Apr 24, 2026
3 checks passed
@mtavenrath mtavenrath deleted the resolve_weights branch April 24, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants