Skip to content

Commit 6dc44fa

Browse files
authored
Merge pull request #53 from ForgeOpus/claude/audit-code-generation-tWPbv
Claude/audit code generation t w pbv
2 parents 09c8711 + 7328ff8 commit 6dc44fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2665
-218
lines changed

project/block_manager/services/codegen/base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ def topological_sort(nodes: List[Dict], edges: List[Dict]) -> List[Dict]:
4444
if in_degree[neighbor] == 0:
4545
queue.append(neighbor)
4646

47+
# Cycle detection: if not all nodes were sorted, there's a cycle
48+
if len(sorted_ids) != len(nodes):
49+
# Find nodes that are still in the cycle (have non-zero in-degree)
50+
cycle_nodes = [node_id for node_id, degree in in_degree.items() if degree > 0]
51+
raise ValueError(
52+
f"Graph contains a cycle. Neural networks must be acyclic (feedforward). "
53+
f"Nodes involved in cycle: {', '.join(cycle_nodes[:5])}"
54+
+ (" and more..." if len(cycle_nodes) > 5 else "")
55+
)
56+
4757
# Return nodes in sorted order
4858
return [node_map[node_id] for node_id in sorted_ids if node_id in node_map]
4959

project/block_manager/services/codegen/base_orchestrator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def _generate_code_specs(
129129

130130
processable_nodes = [
131131
n for n in sorted_nodes
132-
if get_node_type(n) not in ('input', 'dataloader', 'output')
132+
if get_node_type(n) not in ('input', 'dataloader', 'output', 'loss', 'metrics', 'groundtruth')
133133
]
134134

135135
for node in processable_nodes:
@@ -193,7 +193,7 @@ def _generate_forward_pass(
193193

194194
processable_nodes = [
195195
n for n in sorted_nodes
196-
if get_node_type(n) not in ('output',)
196+
if get_node_type(n) not in ('output', 'loss', 'metrics', 'groundtruth')
197197
]
198198

199199
for node in processable_nodes:
@@ -273,7 +273,7 @@ def _generate_config_file(self, nodes: List[Dict[str, Any]]) -> str:
273273
input_shape = self._extract_input_shape(nodes)
274274
layer_count = sum(
275275
1 for n in nodes
276-
if get_node_type(n) not in ('input', 'output', 'dataloader')
276+
if get_node_type(n) not in ('input', 'output', 'dataloader', 'loss', 'metrics', 'groundtruth')
277277
)
278278

279279
if layer_count > 20:

project/block_manager/services/codegen/pytorch_group_generator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def _generate_internal_node_specs(
169169
node_type = get_node_type(node)
170170

171171
# Skip special nodes
172-
if node_type in ('input', 'output', 'dataloader'):
172+
if node_type in ('input', 'output', 'dataloader', 'loss'):
173173
continue
174174

175175
node_id = node['id']
@@ -273,8 +273,8 @@ def _generate_forward_pass(
273273
var_map[node_id] = var_name
274274
continue
275275

276-
# Skip output and dataloader nodes (they don't produce code)
277-
if node_type in ('output', 'dataloader'):
276+
# Skip output, dataloader, and loss nodes (they don't produce code)
277+
if node_type in ('output', 'dataloader', 'loss'):
278278
continue
279279

280280
# Get the spec for this node

0 commit comments

Comments
 (0)