Hi,
I am working with a Hybrid Quantum Classical model, using Pennylane - Torch plugin.
class QuantumModel(nn.Module):
def __init__(self):
super().__init__()
self.q_layer = qml.qnn.TorchLayer(full_circuit, weight_shapes)
self.dropout = nn.Dropout(p=0.5)
self.fc = nn.Linear(n_qubits, n_classes, dtype=torch.float64)
def forward(self, x):
q_out = self.q_layer(x) # Shape: [batch_size, 10]
q_out = self.dropout(q_out) # Apply dropout
logits = self.fc(q_out)
return logits
This is my model framework for the hybrid part. There are classical components also.
I want to ask: Can I measure the FLOPs and MACs the same way as I would for the classical models.
For example, this is a code to measure the FLOPs and MACs for the ResNet50 - My quantum model
from calflops import calculate_flops
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
batch_size = 1
input_shape = (batch_size, 1, 1024)
flops, macs, params = calculate_flops(model=model,
input_shape=input_shape,
output_as_string=True,
output_precision=4)
print("Quantum model FLOPs:%s MACs:%s Params:%s \n" %(flops, macs, params))
from calflops import calculate_flops
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = QuantumModel()
batch_size = 1
input_shape = (batch_size, 1, 1024)
flops, macs, params = calculate_flops(model=model,
input_shape=input_shape,
output_as_string=True,
output_precision=4)
print("Quantum model FLOPs:%s MACs:%s Params:%s \n" %(flops, macs, params))
I have read that the calculate flops library is for any models, provided that the model uses PyTorch. But I am not sure if this is the correct way to calculate the metrics for a quantum model like mine?
Is there any other method to calculate the performance metrics for a quantum model?