NVIDIA / NVIDIA/apex

No speedup on RTX card, how apex affects loss function that uses long float?

Open
#833 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
9k
Forks
1.5k
Avg merge
2d 4h
Merged PRs (30d)
3

Description

My network is a encoder-decoder type, where the encoder uses resnet blocks (so convolution and batch norm). The decoder uses convtranspose and convolution. I am training on RTX2070super, but the apex training is actually slower than the normal one, what may be the issue since my card has tensorcores?
My network requires a custom loss function:

loss = self.loss_func(F.log_softmax(y, 1), yb.long())                                                                                                        

loss1 = self.loss_func(F.log_softmax(y1, 1),                              
                                   F.max_pool2d(yb, kernel_size=2, stride=2,          
                                   padding=0).long())                                                                                                                   
loss2 = self.loss_func(F.log_softmax(y2, 1),                              
                                   F.max_pool2d(yb, kernel_size=4, stride=4,          
                                   padding=0).long())                                                                                                                 

loss3 = self.loss_func(F.log_softmax(y3, 1),                              
                                   F.max_pool2d(yb, kernel_size=8, stride=8,          
                                   padding=0).long())                                                                                                                

loss4 = self.loss_func(F.log_softmax(y4, 1),                              
                                   F.max_pool2d(yb, kernel_size=16, stride=16,        
                                   padding=0).long())                                 
                                                                                 
avg_loss = (loss + (0.9*loss1) + (0.8*loss2) + (0.7*loss3) +              
                    (0.6*loss4))/5   

Where self.loss_func is nn.NLLLoss that appears to require long float as target. My original data target is actually natively float16, may be this conversion a bottleneck? How does apex affect pytorch loss function that use long? Is there any workaround?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by profiling the apex training path around nn.NLLLoss, F.log_softmax, the repeated max_pool2d calls, and the .long() target conversions. Compare it with normal training on the RTX2070super and determine whether target conversion or loss computation accounts for the slowdown; done means the bottleneck and its relationship to apex are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning, performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.