You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@geaflow.apache.org by "qingwen220 (via GitHub)" <gi...@apache.org> on 2025/11/17 09:19:12 UTC

[I] feat: implement GCN based on GeaFlow inference framework. [geaflow]

qingwen220 opened a new issue, #676:
URL: https://github.com/apache/geaflow/issues/676

   **Is your feature request related to a problem? Please describe.**
   A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
   
   **Describe the solution you'd like**
   A clear and concise description of what you want to happen.
   
   **Describe alternatives you've considered**
   A clear and concise description of any alternative solutions or features you've considered.
   
   **Additional context**
   Add any other context or screenshots about the feature request here.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org


Re: [I] feat: implement GCN based on GeaFlow inference framework. [geaflow]

Posted by "aotenjou (via GitHub)" <gi...@apache.org>.
aotenjou commented on issue #676:
URL: https://github.com/apache/geaflow/issues/676#issuecomment-4052954350

   **Implementation Suggestion for Built-in GCN (UDGA)**
   
   A full **GCN** implementation should be provided as a **DSL built-in algorithm (Built-in UDGA)**. On the Java side, the **graph information collection and serialization stage** can reuse the existing **OpenSAGE implementation pattern**, with some simplification in the aggregation logic.
   
   ### Reusable Parts from GraphSAGE
   
   1. **Iterative Sampling**
      In the first iteration, collect all neighbors and perform **fixed-size random sampling (`numSamples`)** on the Java side.
   
   2. **Feature Exchange & Caching**
      Send **messages** to exchange node features with target nodes and store them in the cache (`neighborFeaturesCache`).
   
   3. **Context Construction**
      Concatenate the **center node features** with **neighbor node features** to form a **mini subgraph snapshot**, then pass it as `Object[] modelInputs` into `inferContext.infer(modelInputs)` to perform **cross-process inference on the Python side**.
   
   ### Difference from Standard GraphSAGE
   
   GraphSAGE maintains **neighbor feature arrays with different lengths for each hop (layer)**.
   
   However, a standard **GCN** is conceptually equivalent to **Laplacian matrix multiplication over the entire graph**. In production scenarios with large graphs, a common practical approach is:
   
   * Collect **1-hop and 2-hop neighbors**.
   * Build a **mini-graph subgraph on the Python side** using frameworks such as **PyTorch Geometric (PyG)** or **PGL**.
   * Perform **degree-normalized aggregation in Python**.
   
   This workflow is similar to the `_build_mini_graph` logic in
   `SAGNNTransFormFunctionUDF.py` (see PR #775).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org


Re: [I] feat: implement GCN based on GeaFlow inference framework. [geaflow]

Posted by "kitalkuyo-gita (via GitHub)" <gi...@apache.org>.
kitalkuyo-gita commented on issue #676:
URL: https://github.com/apache/geaflow/issues/676#issuecomment-3550376081

   #  Implementation Plan for GCN Algorithm Based on GeaFlow Inference Framework
   
   ## I. GeaFlow-infer Framework Architecture
   ### 1.1 Core Architecture
   
   GeaFlow-infer is a Java-Python hybrid inference framework with the following core components:
   
   **Java-side Core Components:**
   - **InferContext**: Manages inference context and provides `infer()` interface for model inference
   
   - **InferEnvironmentManager**: Manages Python virtual environment creation and dependency installation
   
   - **Data Exchange Bridge**: Implements efficient Java-Python inter-process data transfer through shared memory queues 
   
   **Python-side Core Components:**
   - **infer_server.py**: Python inference service process that receives data from Java and invokes user-defined inference logic 
   
   - **inferSession.py**: Manages inference sessions, executing model preprocessing, inference, and postprocessing 
   
   ### 1.2 Graph Computing Integration
   
   The inference framework integrates with graph computing through the `IncGraphInferContext` interface
   
   ## II. GCN Algorithm Implementation Design
   
   ### 2.1 Current Implementation Analysis
   
   GeaFlow currently provides a GCN node classification example based on the Cora dataset . This example demonstrates basic node inference workflow but has limitations:
   - Only supports single-node inference, not fully utilizing distributed graph computing capabilities
   - GCN model pre-loads entire graph data on Python side, unsuitable for large-scale graphs
   - Lacks distributed implementation of feature aggregation
   
   ### 2.2 Production-Grade GCN Implementation Architecture
   
   Based on GeaFlow's vertex-centric computing model, I propose the following approach:
   
   #### **Approach A: Mini-Batch Sampling Inference (Recommended)**
   
   ```
   Architecture Flow:
   ┌─────────────────────────────────────────────────────┐
   │  GeaFlow Graph Computing Layer                      │
   │  ┌──────────┐  ┌──────────┐  ┌──────────┐          │
   │  │ Vertex 1 │  │ Vertex 2 │  │ Vertex N │          │
   │  └────┬─────┘  └────┬─────┘  └────┬─────┘          │
   │       │             │             │                 │
   │       └─────────────┴─────────────┘                 │
   │                     │                               │
   │         Neighbor Sampling + Feature Aggregation     │
   │                     │                               │
   └─────────────────────┼───────────────────────────────┘
                         │
            ┌────────────┴────────────┐
            │  Infer Context          │
            │  (Shared Memory Queue)  │
            └────────────┬────────────┘
                         │
   ┌─────────────────────┼───────────────────────────────┐
   │  Python Inference Layer │                           │
   │  ┌──────────────────▼──────────────────┐           │
   │  │  TransFormFunctionUDF               │           │
   │  │  - Receive sampled subgraph         │           │
   │  │  - GCN aggregation computation      │           │
   │  │  - Return node embeddings/predictions│          │
   │  └─────────────────────────────────────┘           │
   └─────────────────────────────────────────────────────┘
   ```
   
   #### **Approach B: Layered Feature Aggregation**
   
   Utilize GeaFlow's multi-round iteration capability to implement GCN's hierarchical message passing.
   
   ## III. Detailed Implementation Plan (Approach A - Recommended)
   
   ### 3.1 Java-side Implementation
   
   #### 3.1.1 GCN Computation Class Structure
   
   Implement based on incremental graph computing interface 
   
   **Core Class Responsibilities:**
   - `GCNCompute`: Extends `IncVertexCentricCompute`, defines GCN algorithm iteration logic
   - `GCNComputeFunction`: Implements `IncVertexCentricComputeFunction`, handles GCN inference for each vertex
   - Integrates inference context
   
   #### 3.1.2 Neighbor Sampling Implementation
   
   ```
   Key Steps:
   1. Obtain K-hop neighbors of nodes (refer to KHop algorithm implementation)
   2. Construct sampled subgraph (node features + edge structure)
   3. Serialize to transferable format
   4. Call infer() interface to send to Python side
   ```
   
   #### 3.1.3 Configuration Management
   
   Required parameters:
   - `INFER_ENV_ENABLE`: Enable inference environment
   - `INFER_ENV_USER_TRANSFORM_CLASSNAME`: Python inference class name
   - `INFER_ENV_INIT_TIMEOUT_SEC`: Environment initialization timeout
   <cite/>
   
   ### 3.2 Python-side Implementation
   
   #### 3.2.1 TransFormFunctionUDF Structure
   
   Implement standard TransFormFunction interface <cite/>
   
   **Core Method Implementation:**
   
   ```python
   class GCNTransFormFunction(TransFormFunction):
       def __init__(self):
           super().__init__(input_size=1)
           # Initialize:
           # 1. Load pre-trained GCN model
           # 2. Set inference device (CPU/GPU)
           # 3. Warm up model
       
       def load_model(self, model_path: str):
           # Load model weights
           # Use torch.jit.script for inference optimization
       
       def transform_pre(self, *args):
           # Input: Sampled subgraph data
           # Process:
           # 1. Parse node feature matrix
           # 2. Construct adjacency matrix/edge index
           # 3. Convert to PyTorch Geometric Data object
           # 4. Execute GCN forward propagation
           # Return: Node embeddings or classification results
       
       def transform_post(self, res):
           # Post-processing: format conversion, normalization, etc.
           return res
   ```
   
   #### 3.2.2 GCN Model Implementation
   
   Build GCN layers using PyTorch Geometric:
   
   **Recommended Model Architecture:**
   - 2-3 GCN convolutional layers
   - Support batch normalization
   - Dropout for overfitting prevention
   - Support edge features (optional)
   
   #### 3.2.3 Dependency Configuration
   
   requirements.txt example 
   
   **Recommended additions:**
   ```
   torch>=1.10.0
   torch-geometric>=2.0.0
   torch-scatter
   torch-sparse
   torch-cluster
   numpy
   scipy
   ```
   
   ### 3.3 Data Flow Design
   
   #### 3.3.1 Feature Data Format
   
   **Java → Python Transfer Format:**
   ```
   {
       "center_node_id": int,
       "sampled_nodes": List[int],
       "node_features": List[List[float]],  // N × D feature matrix
       "edge_index": List[List[int]],       // 2 × E edge index
       "edge_weight": List[float]           // optional
   }
   ```
   
   #### 3.3.2 Result Return Format
   
   **Python → Java Return Format:**
   ```
   {
       "node_id": int,
       "embedding": List[float],      // Node embedding vector
       "prediction": int,             // Classification prediction (node classification task)
       "confidence": float            // Confidence score
   }
   ```
   
   ## IV. Production Environment Optimization Strategies
   
   ### 4.1 Performance Optimization
   
   **1. Batch Processing Optimization**
   - Accumulate multiple node inference requests
   - Use Mini-Batch inference to reduce model invocation frequency
   - Balance batch size and latency
   
   **2. Model Optimization**
   - Use `torch.jit.trace`/`torch.jit.script` to compile model
   - Quantization (INT8 inference)
   - Use ONNX Runtime (optional)
   
   **3. Shared Memory Optimization**
   - Adjust queue size to avoid blocking
   - Use lock-free data structures
   
   **4. Sampling Optimization**
   - Implement intelligent caching mechanism
   - Use importance sampling
   - Pre-compute neighbor sampling
   
   
   ## V. Phased Implementation Plan
   
   ### Phase 1: Basic Framework Setup (1-2 weeks)
   1. Build Java-side GCN computation class framework
   2. Implement Python-side basic TransFormFunction
   3. Complete simple data serialization/deserialization
   4. Verify data flow in single-machine environment
   
   ### Phase 2: Core Algorithm Implementation (2-3 weeks)
   1. Implement neighbor sampling logic
   2. Develop GCN model (training + inference)
   3. Integrate PyTorch Geometric
   4. Functional testing (small-scale graph data)
   
   ### Phase 3: Performance Optimization (2 weeks)
   1. Implement batch inference
   2. Model compilation optimization
   3. Shared memory tuning
   4. Stress testing
   
   ### Phase 4: Production Hardening (1-2 weeks)
   1. Add monitoring instrumentation
   2. Implement fault tolerance mechanisms
   3. Configuration management optimization
   4. Documentation completion
   
   ### Phase 5: Deployment Verification (1 week)
   1. Gradual rollout
   2. Performance baseline establishment
   3. Issue troubleshooting and fixes
   4. Full deployment
   
   ## VI. Risks and Mitigation
   
   ### 7.1 Technical Risks
   
   | Risk Item | Impact | Mitigation |
   |-----------|--------|------------|
   | Python process OOM | Service interruption | Memory monitoring + auto-restart; optimize sampling size |
   | High inference latency | Performance not meeting requirements | Batch processing optimization; model pruning; async inference |
   | Insufficient memory for large graphs | Cannot run | Streaming sampling; feature compression; sharding |
   | Data serialization bottleneck | Low throughput | Use Protocol Buffers; zero-copy |
   
   ### 7.2 Engineering Risks
   
   | Risk Item | Impact | Mitigation |
   |-----------|--------|------------|
   | Python dependency conflicts | Environment initialization failure | Docker containerization; conda environment isolation |
   | Version compatibility | Difficult upgrades | Strict version management; thorough testing |
   | Debugging difficulties | Low development efficiency | Comprehensive logging; local debugging tools |
   
   ## Notes
   
   1. **Limitations of Current Implementation**: The current GeaFlow GCN example is primarily for demonstrating inference framework usage. The model loads the entire graph on the Python side, which is unsuitable for production environments with large-scale graph data.
   
   2. **Challenges of Distributed GCN**: True distributed GCN requires solving cross-node communication issues for feature aggregation. The recommended approach is neighbor sampling + local aggregation to avoid full-graph communication.
   
   3. **Differences from Traditional GNN Frameworks**: GeaFlow-infer is more suitable for inference scenarios rather than training. For training needs, it's recommended to:
      - Train models offline using DGL/PyG
      - Deploy trained models to GeaFlow for large-scale graph inference
      - GeaFlow handles graph data management, sampling, and result aggregation
   
   4. **Extensible Directions**:
      - Support dynamic graph GCN (leveraging GeaFlow's incremental computing capability)
      - Integrate graph embedding pre-computation
      - Implement online learning (Incremental Learning)
   
   5. **Reference Architecture**: This  architecture design draws from classic graph algorithms like PageRank implemented on GeaFlow, adapted for inference framework characteristics.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org


Re: [I] feat: implement GCN based on GeaFlow inference framework. [geaflow]

Posted by "kitalkuyo-gita (via GitHub)" <gi...@apache.org>.
kitalkuyo-gita commented on issue #676:
URL: https://github.com/apache/geaflow/issues/676#issuecomment-3550378416

   Hi community, is anyone interested in this task? I welcome discussion and a proposal to explore this approach. I suggest a phased implementation; this would facilitate review.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org