Skip to content

Commit d3fe9dc

Browse files
authored
Merge pull request #49 from ForgeOpus/main
Fix codeql alert + modularize pytorch codegen
2 parents 1862b00 + 6c62f81 commit d3fe9dc

Some content is hidden

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

75 files changed

+6587
-2592
lines changed

.github/workflows/codeql.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL Advanced"
13+
14+
on:
15+
push:
16+
branches: [ "main", "deploy" ]
17+
pull_request:
18+
branches: [ "main", "deploy" ]
19+
workflow_dispatch:
20+
21+
jobs:
22+
analyze:
23+
name: Analyze (${{ matrix.language }})
24+
# Runner size impacts CodeQL analysis time. To learn more, please see:
25+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
26+
# - https://gh.io/supported-runners-and-hardware-resources
27+
# - https://gh.io/using-larger-runners (GitHub.com only)
28+
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
29+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
30+
permissions:
31+
# required for all workflows
32+
security-events: write
33+
34+
# required to fetch internal or private CodeQL packs
35+
packages: read
36+
37+
# only required for workflows in private repositories
38+
actions: read
39+
contents: read
40+
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
include:
45+
- language: javascript-typescript
46+
build-mode: none
47+
- language: python
48+
build-mode: none
49+
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift'
50+
# Use `c-cpp` to analyze code written in C, C++ or both
51+
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
52+
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
53+
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
54+
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
55+
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
56+
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
57+
steps:
58+
- name: Checkout repository
59+
uses: actions/checkout@v4
60+
61+
# Add any setup steps before running the `github/codeql-action/init` action.
62+
# This includes steps like installing compilers or runtimes (`actions/setup-node`
63+
# or others). This is typically only required for manual builds.
64+
# - name: Setup runtime (example)
65+
# uses: actions/setup-example@v1
66+
67+
# Initializes the CodeQL tools for scanning.
68+
- name: Initialize CodeQL
69+
uses: github/codeql-action/init@v4
70+
with:
71+
languages: ${{ matrix.language }}
72+
build-mode: ${{ matrix.build-mode }}
73+
# If you wish to specify custom queries, you can do so here or in a config file.
74+
# By default, queries listed here will override any specified in a config file.
75+
# Prefix the list here with "+" to use these queries and those in the config file.
76+
77+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
78+
# queries: security-extended,security-and-quality
79+
80+
# If the analyze step fails for one of the languages you are analyzing with
81+
# "We were unable to automatically build your code", modify the matrix above
82+
# to set the build mode to "manual" for that language. Then modify this step
83+
# to build your code.
84+
# ℹ️ Command-line programs to run using the OS shell.
85+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
86+
- name: Run manual build steps
87+
if: matrix.build-mode == 'manual'
88+
shell: bash
89+
run: |
90+
echo 'If you are using a "manual" build mode for one or more of the' \
91+
'languages you are analyzing, replace this with the commands to build' \
92+
'your code, for example:'
93+
echo ' make bootstrap'
94+
echo ' make release'
95+
exit 1
96+
97+
- name: Perform CodeQL Analysis
98+
uses: github/codeql-action/analyze@v4
99+
with:
100+
category: "/language:${{matrix.language}}"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Code generation orchestration package"""
2+
3+
from .pytorch_orchestrator import PyTorchCodeOrchestrator
4+
from .tensorflow_orchestrator import TensorFlowCodeOrchestrator
5+
6+
__all__ = ['PyTorchCodeOrchestrator', 'TensorFlowCodeOrchestrator']
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""
2+
Base utilities for code generation
3+
Shared functions for both PyTorch and TensorFlow code generation
4+
"""
5+
6+
from collections import deque
7+
from typing import List, Dict, Any
8+
9+
10+
def topological_sort(nodes: List[Dict], edges: List[Dict]) -> List[Dict]:
11+
"""
12+
Sort nodes in topological order based on edges using Kahn's algorithm.
13+
14+
Args:
15+
nodes: List of node definitions
16+
edges: List of edge definitions
17+
18+
Returns:
19+
List of nodes in topological order
20+
"""
21+
node_map = {node['id']: node for node in nodes}
22+
23+
# Build adjacency list and in-degree count
24+
graph = {node['id']: [] for node in nodes}
25+
in_degree = {node['id']: 0 for node in nodes}
26+
27+
for edge in edges:
28+
source = edge.get('source')
29+
target = edge.get('target')
30+
if source in graph and target in graph:
31+
graph[source].append(target)
32+
in_degree[target] += 1
33+
34+
# Kahn's algorithm
35+
queue = deque([node_id for node_id, degree in in_degree.items() if degree == 0])
36+
sorted_ids = []
37+
38+
while queue:
39+
node_id = queue.popleft()
40+
sorted_ids.append(node_id)
41+
42+
for neighbor in graph[node_id]:
43+
in_degree[neighbor] -= 1
44+
if in_degree[neighbor] == 0:
45+
queue.append(neighbor)
46+
47+
# Return nodes in sorted order
48+
return [node_map[node_id] for node_id in sorted_ids if node_id in node_map]
49+
50+
51+
def get_input_variable(incoming: List[str], var_map: Dict[str, str]) -> str:
52+
"""
53+
Determine input variable name based on incoming connections.
54+
55+
Args:
56+
incoming: List of incoming node IDs
57+
var_map: Map of node ID to variable name
58+
59+
Returns:
60+
Variable name or list of variable names for multiple inputs
61+
"""
62+
if not incoming:
63+
return 'x'
64+
elif len(incoming) == 1:
65+
return var_map.get(incoming[0], 'x')
66+
else:
67+
# Multiple inputs (for concat, add, etc.)
68+
input_vars = [var_map.get(src, 'x') for src in incoming]
69+
return f"[{', '.join(input_vars)}]"
70+
71+
72+
def get_node_type(node: Dict[str, Any]) -> str:
73+
"""Extract node type from node definition"""
74+
return node.get('data', {}).get('blockType', 'unknown')
75+
76+
77+
def get_node_config(node: Dict[str, Any]) -> Dict[str, Any]:
78+
"""Extract configuration from node definition"""
79+
return node.get('data', {}).get('config', {})

0 commit comments

Comments
 (0)