Skip to content

Simplify axis value checks #1501

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

Merged
merged 1 commit into from
Jul 27, 2021

Conversation

zkneupper
Copy link
Contributor

Simplify axis value checks

Example: replace axis != 1 and axis != 2 with axis not in [1, 2]

@mthrok
Copy link
Contributor

mthrok commented May 13, 2021

Hi @zkneupper

Thanks for the submission. This is very common pattern in Python but this code is also executed by TorchScript runtime. Let us check the performance implication first.

@carolineechen temporarily assigning you. Let's talk about the benchmarking later.

@zkneupper
Copy link
Contributor Author

Hi @zkneupper

Thanks for the submission. This is very common pattern in Python but this code is also executed by TorchScript runtime. Let us check the performance implication first.

@carolineechen temporarily assigning you. Let's talk about the benchmarking later.

Hi @zkneupper

Thanks for the submission. This is very common pattern in Python but this code is also executed by TorchScript runtime. Let us check the performance implication first.

@carolineechen temporarily assigning you. Let's talk about the benchmarking later.

Thanks @mthrok & @carolineechen. Are there tests within the repository for performance benchmarking?

@mthrok
Copy link
Contributor

mthrok commented May 14, 2021

Thanks @mthrok & @carolineechen. Are there tests within the repository for performance benchmarking?

No, there is not. It's simply running the necessary function in timer. It's something like the following.


OMP_NUM_THREADS=1 numactl --membind 0 --cpubind 0 python -m timeit -n 1 -r 5 -s \
'import torch; a = torch.rand(1000, 1000)' \
'a.sum(1)'

This will set the number of threads used to 1 (OMP_NUM_THREADS=1), run the process on NUMA node 0 and memory node 0 (so the memory is being allocated right next to the CPU), runs a.sum(1) once (-n 1) within a benchmark and repeats (-r 5) the benchmark 5 times and executes import torch; a = torch.rand(1000, 1000) at startup.


For this PR, we need to benchmark the function in TorchScript, so in initialization, we first script the function, fun = torch.jit.script(torchaudio.functional.XXX) then run the operation func(...). If you are curious, you can try it before/after the change and give us the report too.

@mthrok mthrok mentioned this pull request May 25, 2021
14 tasks
Copy link
Contributor

@mthrok mthrok left a comment

Choose a reason for hiding this comment

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

Verified that there is no performance degradation in this change with TorchScript.

@mthrok mthrok merged commit d1d6dbc into pytorch:master Jul 27, 2021
nateanl pushed a commit to nateanl/audio that referenced this pull request Jul 28, 2021
mthrok pushed a commit to mthrok/audio that referenced this pull request Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants