DeepLearning For Finance
  • Back to Main Website
  • Home
  • Introduction to Deep Learning
    • Introduction to Deep Learning
    • From Traditional Models to Deep Learning
    • The Multi-Layer Perceptron (MLP)
    • Automatic Differentiation: The Engine of Deep Learning
    • Computation Backends & Keras 3
    • GPUs and Deep Learning: When Hardware Matters
    • Keras Fundamentals: Models & Layers
    • Keras Matrix Operations: The Building Blocks
    • Activation Functions: Adding Non-linearity
    • Model Training Fundamentals

    • Travaux Pratiques
    • TP1 Corrected: Building Neural Networks - From Simple to Custom Implementations
    • TP1 Corrected: Building Neural Networks - From Simple to Custom Implementations
  • Recurrent Neural Networks
    • Recurrent Neural Networks
    • Sequential Data Processing: From MLPs to RNNs
    • Long Short-Term Memory Networks (LSTM)
    • Modern RNN Architectures
    • RNN Limitations: Computational Challenges

    • Travaux Pratiques
    • TP: Recurrent Neural Networks for Time Series Prediction
    • TP Corrected: Recurrent Neural Networks for Time Series Prediction
  • Training a Neural Network
    • Training a Neural Network
    • Understanding the Training Loop
    • Understanding Optimizers
    • Understanding Callbacks
    • Training Parameters and Practical Considerations

    • Travaux Pratiques
    • TP: Using Deep Learning Frameworks for General Optimization
    • tp_general_optimization_corrected.html
    • TP: Impact of Callbacks on Training
  • Essential Building Blocks of Modern Neural Networks
    • Essential Building Blocks of Modern Neural Networks
    • Residual Connections and Gating Mechanisms
    • Convolutional Layers: From Images to Time Series
    • Neural Network Embeddings: Learning Meaningful Representations
    • Attention Mechanisms: Learning What to Focus On
    • Encoder-Decoder Architectures

    • Travaux Pratiques
    • Practical Assignment: Building a Transformer-Based Architecture for Time Series Forecasting
    • Practical Assignment: Building a Transformer-Based Architecture for Time Series Forecasting
  • Projets
    • Projets
  • Code source
  1. Computation Backends & Keras 3
  • Introduction to Deep Learning
  • From Traditional Models to Deep Learning
  • The Multi-Layer Perceptron (MLP)
  • Automatic Differentiation: The Engine of Deep Learning
  • Computation Backends & Keras 3
  • GPUs and Deep Learning: When Hardware Matters
  • Keras Fundamentals: Models & Layers
  • Keras Matrix Operations: The Building Blocks
  • Activation Functions: Adding Non-linearity
  • Model Training Fundamentals
  • Travaux Pratiques
    • TP1 Corrected: Building Neural Networks - From Simple to Custom Implementations
    • TP1 Corrected: Building Neural Networks - From Simple to Custom Implementations

On this page

  • The Stack: From Python to Silicon
    • Section 1.18 - Core Computation Engines
      • TensorFlow (Google)
      • PyTorch (Meta)
      • JAX (Google)
    • Section 1.19 - Keras 3: Unified Abstraction Layer
      • Key Innovation
      • Architecture
    • Section 1.20 - The Performance Layer
      • Under the Hood
      • Example Stack Trace
    • Section 1.21 - Why Abstraction Matters

Computation Backends & Keras 3

Cours
Fundamentals
Understanding the ecosystem of deep learning frameworks and how Keras 3 abstracts hardware acceleration through backend engines.
Author

Remi Genet

Published

2025-04-03

The Stack: From Python to Silicon


Section 1.18 - Core Computation Engines

TensorFlow (Google)

  • Developer: Google Brain Team (2015)
  • Key Trait: Static computation graphs (define-and-run)
  • Strengths:
    • Production-grade deployment (TF Serving, TFLite)
    • Tight TPU integration
  • Weakness: Less flexible for research prototyping

PyTorch (Meta)

  • Developer: Facebook AI Research (2016)
  • Key Trait: Dynamic computation graphs (define-by-run)
  • Strengths:
    • Pythonic debugging experience
    • Dominant in academic research
  • Weakness: Historically weaker mobile/edge support

JAX (Google)

  • Developer: Google Research (2018)
  • Key Trait: Functional programming + composable transforms
  • Strengths:
    • Automatic vectorization (vmap)
    • Native support for higher-order gradients
  • Weakness: Steeper learning curve

Section 1.19 - Keras 3: Unified Abstraction Layer

Key Innovation

Keras 3 acts as a backend-agnostic interface:

# Same code runs on TensorFlow, PyTorch, or JAX
import os
os.environ["KERAS_BACKEND"] = "jax"  # Environment variable needs to be set prior to importing keras, default is tensorflow

from keras import layers

model = keras.Sequential([
    layers.Dense(64, activation='relu'),
    layers.Dense(10)
])

model.compile() 

Architecture

┌──────────────────────────┐
│ Keras API (Python)       │ ← You code here
├──────────────────────────┤
│ Backend Adapter          │ ← Converts Keras ops to backend primitives
├───────┬────────┬─────────┤
│ TF    │ PyTorch│ JAX     │ ← Backend engines
├───────┴────────┴─────────┤
│ XLA/CUDA/C++/ROCm        │ ← Hardware-specific optimization
└──────────────────────────┘

Section 1.20 - The Performance Layer

Under the Hood

All frameworks ultimately delegate computation to:

  1. Optimized C/C++ Kernels:
    • BLAS (e.g., Intel MKL, OpenBLAS) for linear algebra
    • Custom ops for neural networks (e.g., convolution)
  2. GPU Acceleration:
    • CUDA (NVIDIA) / ROCm (AMD) for parallel computation
    • Kernel fusion via XLA (TensorFlow/JAX) or TorchScript (PyTorch)

Example Stack Trace

keras.layers.Dense(..)  # Python
↓
keras.backend.matmul()  # Backend-agnostic op
↓
tf.linalg.matmul()      # TensorFlow implementation
↓
Eigen::Tensor contraction  # C++/CUDA kernel

Section 1.21 - Why Abstraction Matters

  1. Portability: Same model code runs on CPU/GPU/TPU
  2. Vendor Independence: Avoid lock-in to any ecosystem
  3. Performance: Leverage decades of HPC optimization

Back to top
Automatic Differentiation: The Engine of Deep Learning
GPUs and Deep Learning: When Hardware Matters

Deep Learning For Finance, Rémi Genet.
Licence
Code source disponible sur Github

 

Site construit avec et Quarto
Inspiration pour la mise en forme du site ici
Code source disponible sur GitHub