Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Helpers/LayerHelper.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using AiDotNet.NeuralNetworks.Layers.Graph;

namespace AiDotNet.Helpers;

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/LoRA/DefaultLoRAConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using AiDotNet.Interfaces;
using AiDotNet.LoRA.Adapters;
using AiDotNet.NeuralNetworks.Layers;
using AiDotNet.NeuralNetworks.Layers.Graph;

namespace AiDotNet.LoRA;

Expand Down
2 changes: 2 additions & 0 deletions src/NeuralNetworks/GraphNeuralNetwork.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using AiDotNet.NeuralNetworks.Layers.Graph;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Update GraphNeuralNetwork to use IGraphConvolutionLayer<T> and the new SetAdjacencyMatrix/Forward contract

This file still hard-codes GraphConvolutionalLayer<T> and a two-argument Forward that no longer exists, and it ignores the new graph layers that implement IGraphConvolutionLayer<T>.

Concrete issues:

  • Line 532: graphLayer.Forward(current, adjacencyMatrix) no longer compiles because GraphConvolutionalLayer<T> only exposes SetAdjacencyMatrix(Tensor<T>) + Forward(Tensor<T>).
  • Lines 529–545: Only GraphConvolutionalLayer<T> is treated as a graph layer; GraphSAGELayer<T>, GraphAttentionLayer<T>, and GraphIsomorphismLayer<T> (all IGraphConvolutionLayer<T>) will be treated as standard layers and never receive an adjacency matrix. Those layers will throw at runtime when Forward sees a null adjacency.
  • Lines 689–695: Predict skips only GraphConvolutionalLayer<T> but should skip all IGraphConvolutionLayer<T> when adjacency is unavailable.
  • Lines 890–892: GetModelMetadata counts graph layers only via is GraphConvolutionalLayer<T>, so all new graph layers are misclassified as “standard”.

I recommend centralizing on IGraphConvolutionLayer<T> and decoupling adjacency from the specific implementation, e.g.:

-        foreach (var layer in Layers)
-        {
-            if (layer is GraphConvolutionalLayer<T> graphLayer)
-            {
-                current = graphLayer.Forward(current, adjacencyMatrix);
-            }
-            else if (layer is ILayer<T> standardLayer)
-            {
-                // Handle non-graph layers (e.g., Dense, Activation)
-                current = standardLayer.Forward(current);
-            }
-            else
-            {
-                throw new InvalidOperationException($"Unsupported layer type: {layer.GetType().Name}");
-            }
-            ...
-        }
+        foreach (var layer in Layers)
+        {
+            if (layer is IGraphConvolutionLayer<T> graphLayer)
+            {
+                graphLayer.SetAdjacencyMatrix(adjacencyMatrix);
+                current = layer.Forward(current);
+            }
+            else
+            {
+                current = layer.Forward(current);
+            }
+
+            if (current.Rank < 2)
+                throw new InvalidOperationException($"Layer {layer.GetType().Name} produced an invalid output shape.");
+        }

And similarly for Predict and diagnostics:

-            if (Layers[i] is GraphConvolutionalLayer<T>)
+            if (Layers[i] is IGraphConvolutionLayer<T>)
             {
                 // For graph layers, we need adjacency information which is not available
                 // Just pass through without modification for standard prediction
                 continue;
             }
-                { "GraphLayerCount", Layers.Count(l => l is GraphConvolutionalLayer<T>) },
-                { "StandardLayerCount", Layers.Count(l => !(l is GraphConvolutionalLayer<T>)) },
+                { "GraphLayerCount", Layers.Count(l => l is IGraphConvolutionLayer<T>) },
+                { "StandardLayerCount", Layers.Count(l => l is not IGraphConvolutionLayer<T>) },

This will (1) fix the compile-time break with GraphConvolutionalLayer<T>, and (2) ensure all graph layers conforming to IGraphConvolutionLayer<T> are handled consistently.

Also applies to: 529-559, 685-701, 887-893

🤖 Prompt for AI Agents
In src/NeuralNetworks/GraphNeuralNetwork.cs around lines 529-559, 685-701 and
887-893 the code treats only GraphConvolutionalLayer<T> as a graph layer and
calls a non-existent two-argument Forward, causing compile and runtime errors;
change the checks to use the IGraphConvolutionLayer<T> interface, call
SetAdjacencyMatrix(adjacencyMatrix) on that interface (when adjacency is
present) and then call its single-argument Forward(current) (or Forward() as
defined), and update Predict and GetModelMetadata to skip/count all
IGraphConvolutionLayer<T> implementations when adjacency is unavailable; ensure
null-checks for adjacency before calling SetAdjacencyMatrix and handle layers
uniformly via the interface rather than concrete GraphConvolutionalLayer<T>.


namespace AiDotNet.NeuralNetworks;

/// <summary>
Expand Down
Loading
Loading