Identify operations, shapes, parameter usage, and estimate difficulty.
(self)
| 90 | # ----- Analysis ----- |
| 91 | |
| 92 | def analyze(self) -> Dict[str, Any]: |
| 93 | """Identify operations, shapes, parameter usage, and estimate difficulty.""" |
| 94 | analysis: Dict[str, Any] = { |
| 95 | "operations": [], |
| 96 | "estimated_difficulty": "unknown", |
| 97 | "has_parameters": False, |
| 98 | "input_shapes": [], |
| 99 | "forward_lines": 0, |
| 100 | } |
| 101 | |
| 102 | try: |
| 103 | ast.parse(self.source_code) |
| 104 | except SyntaxError: |
| 105 | return analysis |
| 106 | |
| 107 | # Detect common ops by pattern matching |
| 108 | OP_PATTERNS: Dict[str, str] = { |
| 109 | "torch.matmul": "matmul", |
| 110 | "torch.mm": "matmul", |
| 111 | "torch.bmm": "batched_matmul", |
| 112 | "F.linear": "linear", |
| 113 | "nn.Linear": "linear", |
| 114 | "F.relu": "relu", |
| 115 | "F.gelu": "gelu", |
| 116 | "F.silu": "silu", |
| 117 | "F.softmax": "softmax", |
| 118 | "F.layer_norm": "layernorm", |
| 119 | "nn.LayerNorm": "layernorm", |
| 120 | "F.group_norm": "groupnorm", |
| 121 | "nn.GroupNorm": "groupnorm", |
| 122 | "F.conv2d": "conv2d", |
| 123 | "nn.Conv2d": "conv2d", |
| 124 | "F.conv1d": "conv1d", |
| 125 | "nn.Conv1d": "conv1d", |
| 126 | "nn.ConvTranspose2d": "conv_transpose", |
| 127 | "F.batch_norm": "batchnorm", |
| 128 | "nn.BatchNorm2d": "batchnorm", |
| 129 | "nn.BatchNorm1d": "batchnorm", |
| 130 | "F.instance_norm": "instancenorm", |
| 131 | "nn.InstanceNorm2d": "instancenorm", |
| 132 | "F.cross_entropy": "cross_entropy", |
| 133 | "F.mse_loss": "mse_loss", |
| 134 | "F.nll_loss": "nll_loss", |
| 135 | "torch.sum": "reduce_sum", |
| 136 | "torch.mean": "reduce_mean", |
| 137 | "torch.max": "reduce_max", |
| 138 | "torch.sigmoid": "sigmoid", |
| 139 | "torch.tanh": "tanh", |
| 140 | "F.dropout": "dropout", |
| 141 | "nn.Dropout": "dropout", |
| 142 | "F.max_pool2d": "maxpool", |
| 143 | "nn.MaxPool2d": "maxpool", |
| 144 | "F.avg_pool2d": "avgpool", |
| 145 | "nn.AvgPool2d": "avgpool", |
| 146 | "F.interpolate": "interpolate", |
| 147 | "torch.cat": "concat", |
| 148 | "torch.stack": "stack", |
| 149 | "F.embedding": "embedding", |
no outgoing calls
no test coverage detected