torchview icon indicating copy to clipboard operation
torchview copied to clipboard

a llm/vlm usage case

Open simplew2011 opened this issue 5 months ago • 3 comments

Does TorchView support analysis of large models, such as qwen2.5-7b

simplew2011 avatar Nov 04 '25 10:11 simplew2011

Torchview's support does not depend on the size of the model. It essentially records the torch functions during forward propogation. There is a few cases where the network might be cut off (e.g. when you insert numpy op inside the network, by torch.tensor -> numpy.array -> numpy operation -> torch.tensor). So, unless this is done in the model, the model should be supported.

mert-kurttutan avatar Nov 06 '25 19:11 mert-kurttutan

    model_id = "models/Qwen/Qwen2.5-0.5B-Instruct"

    device = 'cpu'
    dtype = 'float16'
    tokenizer = AutoTokenizer.from_pretrained(model_id)
    tokenizer.pad_token = tokenizer.eos_token
    inputs = tokenizer("Hello, my dog is cute", return_tensors="pt").to('cpu')
    model = AutoModelForCausalLM.from_pretrained(
        model_id,
        dtype=getattr(torch, dtype),
        device_map=device,
        trust_remote_code=True
    )
    model_graph1 = draw_graph(
        model, input_data=inputs, graph_name='Qwen2.5-0.5B-Instruct', depth=3, directory='tests1',
        save_graph=True, expand_nested=True, 
        hide_module_functions=True, hide_inner_tensors=True, roll=True, collect_attributes=False
    )
    model_graph1.visual_graph
  • test llm model is ok
  • Do you have plans to add features such as flops, parameters, MACs, read&write @mert-kurttutan

simplew2011 avatar Nov 12 '25 05:11 simplew2011


* test llm model is ok
* Do you have plans to add features such as flops, parameters, MACs, read&write
  [@mert-kurttutan](https://github.com/mert-kurttutan)

Not in the near future. But for a quick solution you can also check torchinfo package that has this implemented.

I am willing to help if there is any PR for this feature.

mert-kurttutan avatar Nov 13 '25 11:11 mert-kurttutan