Skip to content
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

Calculate the number of MACs #41

Open
ChiSu001 opened this issue Sep 29, 2024 · 2 comments
Open

Calculate the number of MACs #41

ChiSu001 opened this issue Sep 29, 2024 · 2 comments

Comments

@ChiSu001
Copy link

ChiSu001 commented Sep 29, 2024

Hi! Can you provide codes to reproduce MACs in Table 6(b) in your paper?
I calculate MACs on multiHMR_896_L using fvcore (https://github.com/facebookresearch/fvcore), but I get different outputs from those in the paper.

Unsupported operator aten::upsample_bicubic2d encountered 1 time(s)
Unsupported operator aten::add encountered 84 time(s)
Unsupported operator prim::PythonOp._Unbind encountered 24 time(s)
Unsupported operator xformers_flash::flash_fwd encountered 24 time(s)
Unsupported operator aten::mul encountered 159 time(s)
Unsupported operator aten::gelu encountered 26 time(s)
Unsupported operator aten::sigmoid_ encountered 1 time(s)
Unsupported operator aten::max_pool2d encountered 1 time(s)
Unsupported operator aten::where encountered 2 time(s)
Unsupported operator aten::repeat encountered 7 time(s)
Unsupported operator aten::ones_like encountered 3 time(s)
Unsupported operator aten::linalg_inv encountered 2 time(s)
Unsupported operator aten::linspace encountered 3 time(s)
Unsupported operator aten::sin encountered 4 time(s)
Unsupported operator aten::cos encountered 3 time(s)
Unsupported operator aten::mul_ encountered 7 time(s)
Unsupported operator aten::_unique2 encountered 1 time(s)
Unsupported operator aten::sub encountered 24 time(s)
Unsupported operator aten::new_ones encountered 1 time(s)
Unsupported operator aten::cumsum encountered 1 time(s)
Unsupported operator aten::add_ encountered 6 time(s)
Unsupported operator aten::rsub encountered 10 time(s)
Unsupported operator aten::softmax encountered 4 time(s)
Unsupported operator aten::linalg_vector_norm encountered 6 time(s)
Unsupported operator aten::clamp_min encountered 3 time(s)
Unsupported operator aten::div encountered 11 time(s)
Unsupported operator aten::sum encountered 2 time(s)
Unsupported operator aten::cross encountered 1 time(s)
Unsupported operator aten::diagonal encountered 1 time(s)
Unsupported operator aten::argmax encountered 1 time(s)
Unsupported operator aten::ne encountered 1 time(s)
Unsupported operator aten::nonzero_numpy encountered 2 time(s)
Unsupported operator aten::clone encountered 3 time(s)
Unsupported operator aten::lt encountered 2 time(s)
Unsupported operator aten::atan2 encountered 1 time(s)
Unsupported operator aten::abs encountered 1 time(s)
Unsupported operator aten::le encountered 1 time(s)
Unsupported operator aten::pow encountered 5 time(s)
Unsupported operator aten::exp encountered 1 time(s)
Unsupported operator aten::eye encountered 2 time(s)
Unsupported operator aten::neg encountered 7 time(s)
Unsupported operator aten::sub_ encountered 1 time(s)
Unsupported operator aten::pad encountered 4 time(s)
Unsupported operator aten::index_select encountered 2 time(s)
The following submodules of the model were never called during the trace of the graph. They may be unused, or they were accessed by direct calls to .forward() or via other python methods. In the latter case they will have zeros for statistics, though their statistics will still contribute to their parent calling module.
backbone.encoder.blocks.0.attn.attn_drop, backbone.encoder.blocks.1.attn.attn_drop, backbone.encoder.blocks.10.attn.attn_drop, backbone.encoder.blocks.11.attn.attn_drop, backbone.encoder.blocks.12.attn.attn_drop, backbone.encoder.blocks.13.attn.attn_drop, backbone.encoder.blocks.14.attn.attn_drop, backbone.encoder.blocks.15.attn.attn_drop, backbone.encoder.blocks.16.attn.attn_drop, backbone.encoder.blocks.17.attn.attn_drop, backbone.encoder.blocks.18.attn.attn_drop, backbone.encoder.blocks.19.attn.attn_drop, backbone.encoder.blocks.2.attn.attn_drop, backbone.encoder.blocks.20.attn.attn_drop, backbone.encoder.blocks.21.attn.attn_drop, backbone.encoder.blocks.22.attn.attn_drop, backbone.encoder.blocks.23.attn.attn_drop, backbone.encoder.blocks.3.attn.attn_drop, backbone.encoder.blocks.4.attn.attn_drop, backbone.encoder.blocks.5.attn.attn_drop, backbone.encoder.blocks.6.attn.attn_drop, backbone.encoder.blocks.7.attn.attn_drop, backbone.encoder.blocks.8.attn.attn_drop, backbone.encoder.blocks.9.attn.attn_drop, smpl_layer.neutral_11, smpl_layer.neutral_11.bm_x, smpl_layer.neutral_11.bm_x.vertex_joint_selector, x_attention_head.transformer.dropout
Total MACs: 1250048563348.0
@fabienbaradel
Copy link
Contributor

Hi @ChiSu001 , which model did you use for computing MACS ?

@ChiSu001
Copy link
Author

ChiSu001 commented Oct 8, 2024

Hi @fabienbaradel , I used multiHMR_896_L.
And I modified the forward_model function in demo.py

def forward_model(model, input_image, camera_parameters,
like this:

def forward_model(model, input_image, camera_parameters,
                  det_thresh=0.3,
                  nms_kernel_size=1,
                 ):
        
    """ Make a forward pass on an input image and camera parameters. """
    from fvcore.nn import FlopCountAnalysis
    from functools import partial

    # Forward the model.
    with torch.no_grad():
        with torch.cuda.amp.autocast(enabled=True):
            model.forward = partial(model.forward, is_training=False, 
                                nms_kernel_size=int(nms_kernel_size),
                                det_thresh=det_thresh,
                                K=camera_parameters)
            flops = FlopCountAnalysis(model, input_image)
            print('Total MACs:', flops.total())
            exit(0)
            humans = model(input_image, 
                           is_training=False, 
                           nms_kernel_size=int(nms_kernel_size),
                           det_thresh=det_thresh,
                           K=camera_parameters)

    return humans

And I got outputs suggested that there were some unsupported operators and the result(1250G) didn't match that(479G) in the paper. It would be much appreciated if you could provide codes for MACS calculation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants