Open MahmoudAshraf97 opened 6 months ago
Note: Links to docs will display an error until the docs builds have been completed.
This comment was automatically generated by Dr. CI and updates every 15 minutes.
Hi @MahmoudAshraf97!
Thank you for your pull request and welcome to our community.
In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.
In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.
Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed
. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.
If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!
I used this compression trick in my Python CTC-based forced alignment: https://github.com/vadimkantorov/ctc/blob/master/ctc.py
And this compression indeed works and helps
In the forced alignment c++ code,
backPtr
is anint8
tensor while only storing the values 0,1, and 2 which can be effectively stored using only 2 bits instead of 8, and since thebackPtr
tensor size islog_probs_len * (targets_length * 2 + 1)
, it can grow to unmanageable sizes in audio files that exceed 2 hours. By using twostd::vector<bool>
to represent the two bits needed forbackPtr
we guarantee that the results are exactly the same while lowering memory usage sincestd::vector<bool>
should use 1 bit to represent a boolean. Best case scenario is memory usage drops to 25%, worst case scenario memory usage doubles if a boolean is represented using 1 byte.From my experiments, the new code can handle longer audio files without running out of memory. I also noticed that on average, only
1-targets_length/log_probs_length
of thebackPtr
array is used (depending on the inputs) so further memory savings can be gained if we used a shape that reduces unused elements.edit: I implemented a better structure for the
backPtr
tensor that still uses two boolean vectors but the numbers of elements are greatly reduced to achieve better memory efficiency. The new structure is similar to a sparse matrix or a list of lists, instead of initializing a complete trellis matrix, we initialize the elements which are only going to be used which is approximated by the formula in the code (deduced empirically and tested thorougly). We also create two new arrays for indexing purposes.