-
Notifications
You must be signed in to change notification settings - Fork 1k
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
APIs - 4.1.0a1 #499
APIs - 4.1.0a1 #499
Conversation
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.
Thanks a lot for all the hard work! Sorry for not commenting before. See my comments, basically aim for a simpler, more compact API, you don't have to support every possible use case!! aim for simplicity and covering 90% of the use case with much simpler code!
I'll update it next week as I have no time this week |
To sum up, the module would look like this:
|
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.
Looks super nice ! we are getting really close :)
@@ -257,6 +257,8 @@ import shlex | |||
demucs.separate.main(shlex.split('--mp3 --two-stems vocals -n mdx_extra "track with space.mp3"')) | |||
``` | |||
|
|||
To use more complicated APIs, see [API docs](docs/api.md) |
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.
The API should be the preferred way :) The shlex
thing is a huge hack. If the API is well done we should totally replace those instructions.
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.
Maybe this API can be kept so users can easier separate an audio without learning how the API works inside another program
callback: A function will be called when the separation of a chunk starts or finished. \ | ||
The argument passed to the function will be a dict. For more information, please see \ | ||
the Callback section. | ||
callback_arg: A dict containing private parameters to be passed to callback function. For \ |
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.
so if we would follow the minimalistic approach, we could get rid of that, that would simplify the _replace_dict logic. Basically if someone wants extra info, they can use partial
from functools
, e.g.
from functools import partial
def callback(args_passed_by_demucs_api, ..., my_arg):
...
api.update_parameters(callback=partial(callback, my_arg=42))
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.
But what if the dictionary key can't be a keyword argument? e.g. begins with numbers like 1st
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.
but that wouldn't be a valid argument to the callback then no ?
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.
The argument of callback is a dict, not keyword arguments.
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.
OK I'll remove callback_arg
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.
I've just realized that my implementation of callback relies on callback_args, so I don't know how to make it better without callback_args
docs/api.md
Outdated
|
||
##### Notes for callback | ||
|
||
The function will be called with only one positional parameter whose type is `dict`. The `callback_arg` will be combined with information of current separation progress. The progress information will override the values in `callback_arg` if same key has been used. |
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.
I'm a bit worried about the pool processing and callback logic, from the look of it it seems like the callback function might get called from different threads which could be a bit dangerous ?
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.
I'll add a thread lock
By the way, how can I abort the separation process using callback? Maybe once the callback returns "break"
, apply_model will return None? But whether this is capable of pool processing?
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.
You can just raise an exception inside the callback, like raise RuntimeError("Interrupted computation")
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.
I just want to make sure that the thread pool will be stopped altogether
Use _NotProvided to allow passing `None` Add returing "break" to stop separation Make callback thread-safe
Two last points: don't drop the callback if not callable, and unsafe usage of lock (use a with statement). Sorry for being a pain, this is such a sensitive part of the code I don't want to end up with some hard to chase bug down the line :) |
Sorry but I can't understand what you mean. If callback is not callable, then an exception will be raised like this: |
Directly calls audio.save_audio Changing parameter `sr` (samplerate) to optional argument Fixes linter
@adefossez Hi, I was wondering if you could provide any additional comments or help with this PR? I'm looking forward to this PR being merged. |
@adefossez Could you please provide your latest suggestions to this PR? |
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.
Looking great thanks so much for the final changes @CarlGao4, and thanks for keeping pushing this, I know this was a bit long :)
I will wait a bit before pushing to PyPI to see if any one comes up with some issues.
APIs - 4.1.0a1 (facebookresearch#499)
No description provided.