77import sys
88from collections .abc import Callable , Generator
99from contextlib import contextmanager
10- from functools import partial
1110from io import TextIOBase
1211from pathlib import Path
1312from types import ModuleType
1615import numpy as np
1716from pydantic import BaseModel
1817
19- from .autodiff_fallbacks import (
20- jacobian_from_jvp ,
21- jacobian_from_vjp ,
22- jvp_from_jacobian ,
23- vjp_from_jacobian ,
24- )
2518from .config import get_config
2619from .logs import get_logger , is_tracing_enabled
2720from .schema_generation import (
@@ -242,27 +235,20 @@ def apply(payload: ApplyInputSchema) -> ApplyOutputSchema:
242235 has_jac = "jacobian" in supported_functions
243236 has_jvp = "jacobian_vector_product" in supported_functions
244237 has_vjp = "vector_jacobian_product" in supported_functions
245- autodiff = get_config ().autodiff_fallbacks
246238
247- if has_jac or ( autodiff and ( has_vjp or has_jvp )) :
239+ if has_jac :
248240 JacobianInputSchema , JacobianOutputSchema = create_autodiff_schema (
249241 api_module .InputSchema , api_module .OutputSchema , ad_flavor = "jacobian"
250242 )
251243
252- if has_jac :
253- _jac_fn = api_module .jacobian
254- elif has_vjp :
255- _jac_fn = partial (jacobian_from_vjp , api_module .vector_jacobian_product , api_module .apply )
256- else :
257- _jac_fn = partial (jacobian_from_jvp , api_module .jacobian_vector_product , api_module .apply )
258-
244+ @assemble_docstring (api_module .jacobian )
259245 def jacobian (payload : JacobianInputSchema ) -> JacobianOutputSchema :
260246 """Computes the Jacobian of the Tesseract.
261247
262248 Differentiates ``jac_outputs`` with respect to ``jac_inputs``, at the point ``inputs``.
263249 """
264250 _trace ("jacobian() called with payload:" , payload )
265- out = _jac_fn (** dict (payload ))
251+ out = api_module . jacobian (** dict (payload ))
266252 result = JacobianOutputSchema .model_validate (
267253 out ,
268254 context = {
@@ -273,62 +259,50 @@ def jacobian(payload: JacobianInputSchema) -> JacobianOutputSchema:
273259 _trace ("jacobian() returned:" , result )
274260 return result
275261
276- if has_jac :
277- jacobian = assemble_docstring (api_module .jacobian )(jacobian )
278262 endpoints .append (jacobian )
279263
280- if has_jvp or ( autodiff and has_jac ) :
264+ if has_jvp :
281265 JVPInputSchema , JVPOutputSchema = create_autodiff_schema (
282266 api_module .InputSchema , api_module .OutputSchema , ad_flavor = "jvp"
283267 )
284268
285- _jvp_fn = api_module .jacobian_vector_product if has_jvp else partial (jvp_from_jacobian , api_module .jacobian )
286-
269+ @assemble_docstring (api_module .jacobian_vector_product )
287270 def jacobian_vector_product (payload : JVPInputSchema ) -> JVPOutputSchema :
288271 """Compute the Jacobian vector product of the Tesseract at the input data.
289272
290273 Evaluates the Jacobian vector product between the Jacobian given by ``jvp_outputs``
291274 with respect to ``jvp_inputs`` at the point ``inputs`` and the given tangent vector.
292275 """
293276 _trace ("jacobian_vector_product() called with payload:" , payload )
294- out = _jvp_fn (** dict (payload ))
277+ out = api_module . jacobian_vector_product (** dict (payload ))
295278 result = JVPOutputSchema .model_validate (
296279 out , context = {"output_keys" : payload .jvp_outputs }
297280 )
298281 _trace ("jacobian_vector_product() returned:" , result )
299282 return result
300283
301- if has_jvp :
302- jacobian_vector_product = assemble_docstring (api_module .jacobian_vector_product )(
303- jacobian_vector_product
304- )
305284 endpoints .append (jacobian_vector_product )
306285
307- if has_vjp or ( autodiff and has_jac ) :
286+ if has_vjp :
308287 VJPInputSchema , VJPOutputSchema = create_autodiff_schema (
309288 api_module .InputSchema , api_module .OutputSchema , ad_flavor = "vjp"
310289 )
311290
312- _vjp_fn = api_module .vector_jacobian_product if has_vjp else partial (vjp_from_jacobian , api_module .jacobian )
313-
291+ @assemble_docstring (api_module .vector_jacobian_product )
314292 def vector_jacobian_product (payload : VJPInputSchema ) -> VJPOutputSchema :
315293 """Compute the vector Jacobian product of the Tesseract at the input data.
316294
317295 Computes the vector Jacobian product between the Jacobian given by ``vjp_outputs``
318296 with respect to ``vjp_inputs`` at the point ``inputs`` and the given cotangent vector.
319297 """
320298 _trace ("vector_jacobian_product() called with payload:" , payload )
321- out = _vjp_fn (** dict (payload ))
299+ out = api_module . vector_jacobian_product (** dict (payload ))
322300 result = VJPOutputSchema .model_validate (
323301 out , context = {"input_keys" : payload .vjp_inputs }
324302 )
325303 _trace ("vector_jacobian_product() returned:" , result )
326304 return result
327305
328- if has_vjp :
329- vector_jacobian_product = assemble_docstring (api_module .vector_jacobian_product )(
330- vector_jacobian_product
331- )
332306 endpoints .append (vector_jacobian_product )
333307
334308 def health () -> dict [str , Any ]:
0 commit comments