-
Notifications
You must be signed in to change notification settings - Fork 902
Support device-level configuration across all devices #1276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support device-level configuration across all devices #1276
Conversation
Thanks for the PR! I think this is a great start for the feature, and in-fact, could be generalized even further to support device-level configuration across all devices. This would mean In other words, something like this: {
"transformers.js_config": {
"device": "webnn-gpu", // Default device
"device_config": {
"webnn": {
"free_dimension_overrides": {
"batch_size": 1,
"num_channels": 3,
"height": 30,
"width": 30
}
},
"webgpu": {
"dtype": "fp16" // when user sets device to webgpu, we will use dtype fp16
}
}
}
} Sure, this may look a bit lengthy, but the goal is to have all these configs generated automatically (especially for webnn-compatible models). What do you think? |
Hi @xenova, that make sense to me. The Transformers.js and device specific configurations will look like:
or
The first one is neater and exclusive, the second one keeps the original config fallback in addition to the device specific configs in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ✅
Will be included in v3.5 release
@xenova Thank you for your code improvements, they have been a great source of inspiration for me. |
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Next step: updating configs on the HF hub. We can prioritize some of the more popular models, and make automated PRs for models which ordinarily only support static shapes. Although, we'll need to decide what shapes to use when the model allows dynamic shapes. I.e., it is easy for models like https://huggingface.co/Xenova/slimsam-77-uniform for which we define values in the preprocessor_config.json (e.g., here), but for models like MODNet, which support dynamic shapes, deciding the size to use is a bit trickier. |
Currently setting free_dimension_override at a model level would restrict the models which can handle dynamic shapes, which impacts cpu, webgpu and node.js...
This PR changed the logic a little bit that only allow free_dimension_override on a device level, and work under
webnn
key only oftransformers.js_config
in config.json.Tested pass by using
xenova/resnet-50
with updated localconfig.js
file and didn't setfree_dimension_overrides
in app JavaScript code.@xenova PTAL
CC @Honry @huningxin