1#![deny(unsafe_code)]
111#![allow(clippy::result_large_err)]
112
113pub mod advanced_grad_ops;
114pub mod amp_policy;
116pub mod boolean_indexing;
117pub mod checkpointing;
118pub mod context;
119pub mod coverage_matrix;
120pub mod custom_gradients;
121pub mod debug;
122pub mod deterministic;
123pub mod device_placement;
124pub mod efficient_memory;
125pub mod ellipsis_newaxis;
126pub mod error_taxonomy;
127pub mod forward_ad;
128pub mod forward_reverse;
129pub mod global_pooling;
130pub mod gpu_gradient_expansion;
131pub mod grad_ops;
132pub mod gradient_accumulation;
133pub mod gradient_analyzer;
134pub mod gradient_buffer_manager_simple;
135pub mod gradient_compression;
136pub mod gradient_compression_advanced;
137pub mod gradient_ops;
138pub mod gradient_utils;
139pub mod gradient_visualization;
141pub mod graph_optimization;
142pub mod higher_order;
143pub mod hybrid_scheduler;
144pub mod implicit_differentiation;
145pub mod inplace_ops;
146pub mod jit_compiler;
147pub mod jit_integration;
148pub mod kernel_fusion;
149pub mod memory_diff_reporter;
150pub mod memory_profiler;
151pub mod neural_integration;
152pub mod no_grad;
153pub mod numerical_checker;
154pub mod ops;
155#[cfg(feature = "parallel")]
156pub mod parallel_gradients;
157pub mod parameter_server;
158pub mod performance_benchmark;
159pub mod second_order;
160pub mod second_order_utils;
161pub mod simd_grad_ops_simple;
162pub mod special_functions;
163pub mod subgraph_extraction;
164pub mod tape;
165pub mod tape_optimization;
166pub mod tensor_ext;
167pub mod tensor_networks;
168pub mod ultra_gradient;
169pub mod ultra_gradient_engine_simple;
170
171pub use boolean_indexing::{
172 boolean_mask_backward, integer_array_indexing_backward, where_backward,
173};
174pub use checkpointing::{
175 checkpoint_sequence, ActivationCheckpointPolicy, ActivationCheckpointing,
176 ActivationRecomputeManager, CheckpointManager, CheckpointStrategy, CheckpointedFunction,
177 CheckpointedGradientTape, CheckpointingStats, LayerMetadata, RecomputationContext,
178};
179pub use context::{AutogradContext, ShapeInferenceRule, StaticShapeInference};
180pub use coverage_matrix::{
181 CategoryCoverage, CoverageMatrix, CoverageReport, OperationCategory, OperationMetadata,
182};
183pub use custom_gradients::{
184 CustomGradientFunction, CustomGradientOp, GradientClipFunction, GradientScaleFunction,
185 StopGradientFunction,
186};
187pub use debug::{GradientDebugInfo, GradientDebugger};
188pub use deterministic::{
189 clear_operation_seeds, get_global_seed, get_operation_seed, get_seeded_operation_count,
190 hash_tensor_data, is_deterministic, reset_deterministic_state, set_deterministic,
191 set_global_seed, set_operation_seed, DeterministicConfig, DeterministicContext,
192 DeterministicOperation, ReproducibilityChecker, ReproducibilityStats, SeedManager,
193};
194pub use device_placement::{
195 DevicePlacementConfig, DevicePlacementOptimizer, GraphOperation, PlacementDecision,
196 PlacementResult, PlacementStrategy,
197};
198pub use ellipsis_newaxis::{ellipsis_newaxis_backward, AdvancedIndexer, IndexSpec};
199pub use error_taxonomy::{
200 utils as error_utils, AutogradErrorBuilder, ErrorPatternValidator, GradientContext,
201 ValidationResult,
202};
203pub use forward_ad::{forward_ops, DualTensor, ForwardADContext, ForwardMode};
204pub use forward_reverse::{
205 ComplexityEstimate, DifferentiationMode, ForwardReverseConfig, ForwardReverseDifferentiator,
206};
207pub use global_pooling::{
208 adaptive_avg_pool2d_backward, adaptive_max_pool2d_backward,
209 fractional_adaptive_avg_pool2d_backward, global_avg_pool2d_backward,
210 global_max_pool2d_backward,
211};
212pub use gpu_gradient_expansion::{
213 GpuCategoryCoverage, GpuCoverageAnalysis, GpuGradInfo, GpuGradStatus, GpuGradientPlanner,
214 ImplementationPlan, ImplementationTask, Priority,
215};
216pub use grad_ops::{
217 batch_fused_activations_forward_backward, fused_gelu_forward_backward,
218 fused_log_softmax_forward_backward, fused_tanh_forward_backward,
219};
220#[cfg(feature = "parallel")]
221pub use gradient_accumulation::{
222 accumulate_gradients_distributed, DistributedGradientAccumulator, DistributedStats,
223};
224pub use gradient_accumulation::{accumulate_gradients_over_batch, GradientAccumulator};
225pub use gradient_buffer_manager_simple::{
226 global_gradient_buffer_manager, AllocationMetrics, EfficiencyMetrics, GradientBufferAllocation,
227 GradientBufferConfig, GradientBufferManager, GradientMemoryStatistics,
228 MemoryPressureStatistics,
229};
230pub use gradient_compression::{
231 CompressedGradient, CompressionConfig, CompressionMethod, CompressionStats, GradientCompressor,
232};
233pub use gradient_ops::{
234 accumulate_gradients, add_gradient_noise, average_gradients, clip_by_global_norm,
235 clip_by_value, compute_gradient_statistics, has_invalid_gradients, scale_gradients,
236 zero_gradients, GradientPipeline, GradientStatistics, NamedGradientAccumulator,
237};
238pub use gradient_visualization::{
239 ColorScheme, EdgeType, GradientFlowAnalysis, GradientFlowEdge, GradientFlowIssue,
240 GradientFlowNode, GradientFlowVisualizer, GradientStats, IssueType, LayoutAlgorithm, NodeType,
241 OutputFormat, Severity, ValueStats, VisualizationSettings,
242};
243pub use graph_optimization::{
244 CommunicationPlan, EnhancedGraphOptimizer, GradientFusion, GraphOptimizationConfig,
245 GraphOptimizationResult, MemoryOptimization,
246};
247pub use hybrid_scheduler::{
248 ExecutionStats, ExecutionSummary, GraphAnalysis, HybridScheduler, SchedulerConfig, StrategyCost,
249};
250pub use implicit_differentiation::{
251 FixedPointFunction, GradientInfo, ImplicitDiffConfig, ImplicitDifferentiator, ImplicitFunction,
252 OptimizationLayer,
253};
254pub use inplace_ops::{InPlaceOptimizer, InPlaceSequenceOptimizer};
255pub use jit_compiler::{
256 CompiledKernel, DeviceFeatures, GradientKernelTemplate, JitCompiler, KernelPerformance,
257 KernelSignature, OptimizationLevel,
258};
259pub use jit_integration::{utils as jit_utils, JitConfig, JitGradientContext, JitGradientTapeExt};
260pub use kernel_fusion::{FusableOp, FusedKernel, FusionStats, KernelFusionOptimizer, OpSequence};
261pub use memory_diff_reporter::{MemoryDiff, MemoryDiffReporter, MemorySnapshot};
262pub use memory_profiler::{get_global_profiler, GradientMemoryProfiler, MemoryReport, MemoryStats};
263pub use neural_integration::{
264 AutogradLayer, AutogradOptimizer, AutogradTrainer, OptimizerType, TrainingMetrics,
265};
266pub use no_grad::{
267 enable_grad, is_grad_enabled, no_grad, set_grad_enabled, EnableGradGuard, NoGradGuard,
268};
269pub use numerical_checker::{
270 CheckerConfig, ErrorAnalysis, FiniteDifferenceMethod, GradientCheckResult, NumericalChecker,
271};
272#[cfg(feature = "parallel")]
273pub use parallel_gradients::{
274 AsyncGradientHandle, CommunicationBackend, GradientTask, ParallelGradientConfig,
275 ParallelGradientConfigBuilder, ParallelGradientEngine, ParallelGradientResult, PipelineConfig,
276};
277pub use parameter_server::{
278 FaultToleranceMode, LoadBalancingStrategy, ParameterServer, ParameterServerClient,
279 ParameterServerConfig, ParameterServerStats,
280};
281pub use performance_benchmark::{
282 BenchmarkConfig, BenchmarkReport, BenchmarkResult, BenchmarkStatistics, BenchmarkSummary,
283 ComparisonResult, PerformanceBenchmark, RegressionReport, RegressionSeverity,
284 ThroughputMetrics,
285};
286pub use simd_grad_ops_simple::{
287 global_simd_grad_ops, SimdGradConfig, SimdGradOps, SimdPerformanceMetrics,
288};
289pub use special_functions::{
290 bessel_j0_backward, bessel_j1_backward, beta_backward, digamma_backward, erf_backward,
291 erfc_backward, gamma_backward, lgamma_backward,
292};
293pub use subgraph_extraction::{
294 ExtractionStrategy, Subgraph, SubgraphConfig, SubgraphExtractionResult, SubgraphExtractor,
295 SubgraphOperation,
296};
297pub use tape::{GradientTape, Operation, TapeNode, TrackedTensor};
298pub use tape_optimization::{TapeOptimizationConfig, TapeOptimizationStats, TapeOptimizer};
299pub use tensor_ext::TensorAutograd;
300pub use tensor_networks::{
301 ContractionEdge, ContractionPath, ContractionStep, ContractionStrategy, TensorNetwork,
302 TensorNetworkGradient, TensorNetworkNode, TensorNetworkOptimizer,
303};
304pub use ultra_gradient_engine_simple::{
305 global_ultra_gradient_engine, GradientMemoryStats, GradientPerformanceMetrics,
306 OptimizationInsights, UltraGradientConfig, UltraGradientEngine, UltraGradientResult,
307 UltraGradientTapeExt,
308};
309
310use tenflowers_core::{Result, Tensor};
311
312pub use advanced_grad_ops::{
313 gradient_clipping, higher_order as advanced_higher_order, jacobian, optimization,
314 AdaptiveGradientAccumulator,
315};
316pub use amp_policy::{
317 AMPConfig, AMPPolicy, AMPStabilityMetrics, ScaleAdjustment, ScaleAdjustmentReason,
318};
319pub use efficient_memory::{
320 AggregationStats, CheckpointStats, GradientCheckpointer, GradientMemoryManager,
321 GradientMemoryPool, LazyGradient, MemoryManagerStats, MemoryPoolStats,
322 StreamingGradientAggregator,
323};
324pub use gradient_analyzer::{
325 AnalysisConfig, GradientAnalysisReport, GradientAnalyzer,
326 GradientFlowAnalysis as AdvancedGradientFlowAnalysis, GradientIssue,
327 GradientStatistics as AnalyzerGradientStatistics, PerformanceMetrics,
328};
329pub use second_order_utils::{
330 compute_hessian, compute_hessian_diagonal, compute_jacobian, compute_laplacian,
331 directional_second_derivative, hessian_vector_product,
332};
333
334pub trait Differentiable<T> {
335 fn backward(&self, grad_output: &Tensor<T>) -> Result<Vec<Tensor<T>>>;
336 fn grad(&self) -> Option<&Tensor<T>>;
337}