7 PyTorch Tips You Should Know

  Рет қаралды 21,073

Edan Meyer

Edan Meyer

Күн бұрын

GitHub link: gist.github.co...
Here are 7 tips for improving your PyTorch skills. These are all things that I thought of because I use on a normal basis. PyTorch has a lot of need things you can do with modeling to distributions, let me know other tips you have in the comments below!
Tips:
1. Create tensors directly on the target device
2. Use Sequential layers when possible
3. Don't make lists of layers
4. Make use of distributions
5. Use the detach method when the gradient is not needed
6. How to delete a model from the GPU
7. Call the eval method before testing

Пікірлер: 32
@kuretaxyz
@kuretaxyz 2 жыл бұрын
You can also initialize Sequential layer with an OrderedDict if you want to access the layers with names instead of list indices.
@snippletrap
@snippletrap Жыл бұрын
Converting a list of layers to a Sequential module is not always best. For example, suppose you want to add positional embeddings to each intermediate output. Can't do that with Sequential. But you can use a ModuleList as if it's a vanilla Python list, and the parameters will be visible to both the optimizer and the GPU.
@scottmiller2591
@scottmiller2591 Жыл бұрын
I would run into the need to use gc and clear the cache when running pytorch lightning. If allowed to stop on its own, lightning would clean up after itself, but at least in preliminary runs, you'd see things were going south or want to stop iterating for some other reason, and breaking the iteration loop in lightning before it completed its iterations would leave all kinds of garbage (the still-loaded models, etc.) on the GPUs, as you could easily test by looking at nvidia-smi - the memory would still be in use, even though lightning was supposed to release it. I can't remember if I used your exactly your lines, but I ran something to clean up the GPUs. It convinced me (along with the relative inflexibility of lightning) to stop using lightning. I don't know if the lightning devs have cleaned this up in the intervening 4 years, but it's something to keep in mind.
@talkingbirb2808
@talkingbirb2808 2 жыл бұрын
3rd tip: use torch.nn.ModuleList instead of list
@PritishMishra
@PritishMishra 2 жыл бұрын
Amazing video! I didn't knew adding device='cuda' can make such difference!
@edgostyn
@edgostyn Жыл бұрын
Thank you very much, Edan. Hugs from Brazil!
@haritoshpatel4216
@haritoshpatel4216 2 жыл бұрын
I am a PhD student focusing on machine learning and I can assure you these are amazing starter tips - sometimes I even forget occasionally the .eval one xD
@henryhsu9517
@henryhsu9517 Жыл бұрын
5:24 essential issue! Thank you for sharing.
@mariusfacktor3597
@mariusfacktor3597 2 жыл бұрын
Great video! I like to find out what other PyTorch users think about, and these are some helpful "best practices"
@pritamkarmokar3674
@pritamkarmokar3674 2 жыл бұрын
Thank you for the video. It could have been better if the display were zoomed in a bit more.
@stracci_5698
@stracci_5698 2 жыл бұрын
Tip number one and already got my like 🤯
@zenchiassassin283
@zenchiassassin283 8 ай бұрын
Another tip: use torch.no_grad() or torch.inference_mode() at evaluation time
@pullrequest1296
@pullrequest1296 2 жыл бұрын
The test time of the first case is obviously not correct since you do not synchronize before measuring time.
@hassanhamidi7079
@hassanhamidi7079 2 жыл бұрын
Great video. Keep making videos like this, please
@caiyu538
@caiyu538 7 ай бұрын
Great lectures.
@timangar9771
@timangar9771 3 жыл бұрын
Very cool, thanks :)
@nintishia
@nintishia 2 жыл бұрын
Great tips. Thanks.
@1331death
@1331death Жыл бұрын
Why deploying in PyTorch is not the best option?
@fabiolaespinoza778
@fabiolaespinoza778 2 жыл бұрын
Thanks for the video ! For the 6th trick, do you know if replacing the model's instance frees up memory or does it accumulate? For example, if I first train a model using the instance name 'example_model' and then train another model with the same name, in terms of memory will I be accumulating the 2 models' space? Or just the last? Thanks!
@EdanMeyer
@EdanMeyer 2 жыл бұрын
Not 100% sure, but I believe that if you reassign the value of the model, then that should delete the model according to Python's standard garbage collection implementation. However, if you have any separate references to it, those would also need to be deleted. Once there are no references left, it should be put in the garbage collection queue, and will then be deleted at some point in the future when the space is needed.
@fabiolaespinoza778
@fabiolaespinoza778 2 жыл бұрын
Ok, thanks for the reply!
@user-wr4yl7tx3w
@user-wr4yl7tx3w Жыл бұрын
Is Pytorch as good as TF for high performance?
@ssshukla26
@ssshukla26 3 жыл бұрын
Subscribed...
@mingleiyin2154
@mingleiyin2154 3 жыл бұрын
super useful
@wretchedmoose5139
@wretchedmoose5139 3 жыл бұрын
i dont get coding but this make me want to understand it
@mamotivated
@mamotivated 2 жыл бұрын
Rock solid
@jargolauda2584
@jargolauda2584 Жыл бұрын
please use a bigger font in the video. code is taking oly 1/3 of the screen width, so there is empty space for bigger font, for us TV tubers and couch programmers
@mohamedmesto3644
@mohamedmesto3644 Жыл бұрын
nice
@MadlipzMarathi
@MadlipzMarathi Жыл бұрын
Use pytorch lighting you will avoid 70% of your mistakes
@736939
@736939 Жыл бұрын
Actually instead of the list it's better to use nn.ModuleList().
PYTORCH COMMON MISTAKES - How To Save Time 🕒
19:12
Aladdin Persson
Рет қаралды 55 М.
Vim Tips I Wish I Knew Earlier
23:00
Sebastian Daschner
Рет қаралды 65 М.
HAH Chaos in the Bathroom 🚽✨ Smart Tools for the Throne 😜
00:49
123 GO! Kevin
Рет қаралды 13 МЛН
отомстил?
00:56
История одного вокалиста
Рет қаралды 6 МЛН
Magic or …? 😱 reveal video on profile 🫢
00:14
Andrey Grechka
Рет қаралды 89 МЛН
PyTorch Hooks Explained - In-depth Tutorial
22:08
Elliot Waite
Рет қаралды 35 М.
PyTorch Performance Tuning Guide - Szymon Migacz, NVIDIA
26:42
Arun Mallya
Рет қаралды 21 М.
PyTorch Crash Course - Getting Started with Deep Learning
49:55
AssemblyAI
Рет қаралды 96 М.
Introducing 0DE5
39:38
Kay Lack
Рет қаралды 71 М.
Model Based RL Finally Works!
28:01
Edan Meyer
Рет қаралды 34 М.
Python Reinforcement Learning using Stable baselines. Mario PPO
37:24
Diffie-Hellman Key Exchange: How to Share a Secret
9:09
Spanning Tree
Рет қаралды 149 М.
Visualizing activations with forward hooks (PyTorch)
18:58
mildlyoverfitted
Рет қаралды 14 М.
HAH Chaos in the Bathroom 🚽✨ Smart Tools for the Throne 😜
00:49
123 GO! Kevin
Рет қаралды 13 МЛН