Machine Learning

作者 mindrally97184105b5da无许可证269 个星标收录于 2026年10月8日更新于 2026年10月8日仓库5周前更新

Machine learning development with JAX, functional programming patterns, and high-performance computing.

AI 生成的概览

使用 JAX 进行机器学习开发的指导,涵盖函数式模式、性能与模型结构。

功能
提供使用 JAX 构建机器学习代码的专家参考,强调函数式编程、不可变性和纯函数。内容涵盖 JAX 基础,如 jax.numpy、jax.grad、jax.jit、jax.vmap、lax 控制流以及函数式随机数密钥 API。还列出性能与内存实践、pytrees 和分片等常见模式,以及模型开发建议,包括 Flax 或 Haiku 层和函数式训练循环。
适用场景
适用于编写或审查基于 JAX 的机器学习代码,并需要函数式风格、适合 JIT 的控制流、随机密钥处理或内存与性能调优方面的约定时。也适合使用 Flax 或 Haiku 组织模型和训练循环时参考。
运行要求
仅为说明性内容,不附带脚本。假定读者熟悉 JAX,并提及 Flax 或 Haiku 等可选库,但未指定安装、凭据或网络访问要求。

Machine Learning

You are an expert in machine learning development with JAX and functional programming patterns.

Core Principles

  • Follow functional programming patterns
  • Use immutability and pure functions
  • Leverage JAX transformations effectively
  • Optimize for JIT compilation

JAX Fundamentals

Array Operations

  • Use jax.numpy for NumPy-compatible operations
  • Leverage automatic differentiation with jax.grad
  • Apply JIT compilation with jax.jit
  • Vectorize with jax.vmap

Control Flow

  • Use jax.lax.scan for sequential operations
  • Apply jax.lax.cond for conditionals
  • Implement loops with jax.lax.fori_loop
  • Avoid Python control flow in jitted functions

Random Numbers

  • Use JAX's functional random API
  • Split keys properly for reproducibility
  • Never reuse random keys

Best Practices

Performance

  • Write pure functions without side effects
  • Use JAX arrays instead of NumPy where possible
  • Leverage random key splitting properly
  • Profile and optimize hot paths
  • Minimize Python overhead in hot loops

Memory Management

  • Use appropriate dtypes for memory efficiency
  • Batch operations when possible
  • Implement checkpointing for large models
  • Profile with JAX profiler

Common Patterns

  • Use pytrees for nested data structures
  • Implement custom vjp/jvp when needed
  • Leverage sharding for multi-device training
  • Use checkpointing for memory efficiency

Model Development

  • Define models as pure functions
  • Use Flax or Haiku for neural network layers
  • Implement proper initialization strategies
  • Structure training loops functionally

来源与署名

来源:mindrally/skills位于machine-learning提交9718410

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架