FTorch
FTorch copied to clipboard
Subroutine for printing model layer weights
Discussed in https://github.com/Cambridge-ICCS/FTorch/discussions/419
Originally posted by rgknox August 5, 2025 Hello. I've generated a trained neural network model in pytorch, and loaded it with Ftorch with the intention of performing inference. But I'd like to verify that I am writing and loading what I think I am, by printing the weights on both sides of the process. In my case it is just a couple of small linear layers and a relu.
In pytorch, I can loop through the items in the state_dict, like so:
state_dict = model.state_dict()
for name, tensor in state_dict.items():
print(f"Parameter: {name}")
print(tensor)
Are there wrapper functions on the FTorch side that can help with this? I see there is a wrapper for printing out the contents of a tensor, but I'm not sure how to loop through the contents of the model and access those tensors. Thank you for your help!