deepspeedai / deepspeedai/DeepSpeed

[BUG] FlopsProfiler cannot handle input of type torch.nn.utils.rnn.PackedSequence

Open
#4,333 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug inference
Dominant language
Python
Stars
43.1k
Forks
5k
Avg merge
4d 15h
Merged PRs (30d)
112

Description

Describe the bug
When I try to run deepspeed.profiling.flops_profiler.get_model_profile() as shown in the tutorial to profile a two-layer OpenNMT LSTM model, the profiling crashes with the following error message:

File "~/mambaforge/envs/avhubert/lib/python3.8/site-packages/deepspeed/profiling/flops_profiler/profiler.py", line 1017, in _rnn_forward_hook
    batch_size = inp.shape[0]
AttributeError: 'PackedSequence' object has no attribute 'shape'  

To Reproduce
I don't have any simple scripts for reproducing the error, but running profiler on any RNN model where inputs are wrapped inside torch.nn.utils.rnn.PackedSequence should do.

Expected behavior
In PackedSequence, the input tensor is stored inside a variable called data. For my own needs, I resolved this issue by changing lines 1013-1014 in the profiler.py to

if isinstance(inp, nn.utils.rnn.PackedSequence):
    batch_size = inp.data.shape[0]
    seq_length = inp.data.shape[1]
else:
    batch_size = inp.shape[0]
    seq_length = inp.shape[1]

ds_report output

[2023-09-14 12:01:43,772] [INFO] [real_accelerator.py:158:get_accelerator] Setting ds_accelerator to cuda (auto detect)
--------------------------------------------------
DeepSpeed C++/CUDA extension op report
--------------------------------------------------
NOTE: Ops not installed will be just-in-time (JIT) compiled at
      runtime if needed. Op compatibility means that your system
      meet the required dependencies to JIT install the op.
--------------------------------------------------
JIT compiled ops requires ninja
ninja .................. [OKAY]
--------------------------------------------------
op name ................ installed .. compatible
--------------------------------------------------
 [WARNING]  async_io requires the dev libaio .so object and headers but these were not found.
 [WARNING]  async_io: please install the libaio-dev package with apt
 [WARNING]  If libaio is already installed (perhaps from source), try setting the CFLAGS and LDFLAGS environment variables to where it can be found.
async_io ............... [NO] ....... [NO]
fused_adam ............. [NO] ....... [OKAY]
cpu_adam ............... [NO] ....... [OKAY]
cpu_adagrad ............ [NO] ....... [OKAY]
fused_lamb ............. [NO] ....... [OKAY]
quantizer .............. [NO] ....... [OKAY]
random_ltd ............. [NO] ....... [OKAY]
 [WARNING]  please install triton==1.0.0 if you want to use sparse attention
sparse_attn ............ [NO] ....... [NO]
spatial_inference ...... [NO] ....... [OKAY]
transformer ............ [NO] ....... [OKAY]
stochastic_transformer . [NO] ....... [OKAY]
transformer_inference .. [NO] ....... [OKAY]
--------------------------------------------------
DeepSpeed general environment info:
torch install path ............... ['~/mambaforge/envs/avhubert/lib/python3.8/site-packages/torch']
torch version .................... 1.13.1
deepspeed install path ........... ['~/mambaforge/envs/avhubert/lib/python3.8/site-packages/deepspeed']
deepspeed info ................... 0.10.2, unknown, unknown
torch cuda version ............... 11.6
torch hip version ................ None
nvcc version ..................... 11.6
deepspeed wheel compiled w. ...... torch 1.13, cuda 11.6
shared memory (/dev/shm) size .... 31.24 GB

Screenshots
None.

System info (please complete the following information):

  • OS: Ubuntu 20.04
  • GPU count and types: one NVIDIA GeForce RTX 2080 Ti
  • Python version: 3.8.17

Docker context
None.

Additional context
None.

Contributor guide

Open the contributing guide

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

Read deepspeed/profiling/flops_profiler/profiler.py around lines 1013-1017, especially _rnn_forward_hook, and run the FlopsProfiler tutorial flow with an RNN receiving a PackedSequence. Done means profiling handles PackedSequence inputs without the reported AttributeError while preserving existing handling for regular tensor inputs.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning, performance
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.