code: def _dupire_local_volatility_prices(
      time,
      spot_price,
      initial_spot_price,
      implied_volatility_surface,
      discount_factor_fn,
      dividend_yield,
  ):
      """Constructs local volatility function using Dupire's formula.
  
      Args:
        time: A real `Tensor` of shape compatible with `spot_price` specifying the
          times at which local volatility function is computed.
        spot_price: A real `Tensor` specifying the underlying price at which local
          volatility function is computed.
        initial_spot_price: A real `Tensor` of shape compatible with `spot_price`
          specifying the underlying spot price at t=0.
        implied_volatility_surface: A Python callable which implements the
          interpolation of market implied volatilities. The callable should have the
          interface `implied_volatility_surface(strike, expiry_times)` which takes
          real `Tensor`s corresponding to option strikes and time to expiry and
          returns a real `Tensor` containing the corresponding market implied
          volatility. The shape of `strike` is `(n,dim)` where `dim` is the
          dimensionality of the local volatility process and `t` is a scalar tensor.
          The output from the callable is a `Tensor` of shape `(n,dim)` containing
          the interpolated implied volatilties.
        discount_factor_fn: A python callable accepting one real `Tensor` argument
          time t. It should return a `Tensor` specifying the discount factor to time
          t.
        dividend_yield: A real `Tensor` of shape compatible with `spot_price`
          specifying the (continuously compounded) dividend yield.
  
      Returns:
        A real `Tensor` of same shape as `spot_price` containing the local
        volatility computed at `(spot_price,time)` using Dupire's
        construction of local volatility.
      """
      dtype = time.dtype
  
      risk_free_rate_fn = _get_risk_free_rate_from_discount_factor(
          discount_factor_fn
      )
      risk_free_rate = tf.convert_to_tensor(
          risk_free_rate_fn(time), dtype=dtype
      )
  
      def _option_price(expiry_time, strike):
          discount_factors = tf.convert_to_tensor(
              discount_factor_fn(expiry_time), dtype=dtype
          )
          vols = implied_volatility_surface(
              strike=strike, expiry_times=expiry_time
          )
          c_k_t = black_scholes.option_price(
              volatilities=vols,
              strikes=strike,
              expiries=expiry_time,
              spots=initial_spot_price,
              dividend_rates=dividend_yield,
              discount_factors=discount_factors,
              dtype=dtype,
          )
          return c_k_t
  
      dcdk_fn = lambda x: _option_price(time, x)
      dcdt_fn = lambda x: _option_price(x, spot_price)
      d2cdk2_fn = lambda x: math.fwd_gradient(dcdk_fn, x)
  
      # TODO(b/173568116): Replace gradients of call prices with imp vol gradients.
      numerator = (
          math.fwd_gradient(dcdt_fn, time)
          + (risk_free_rate - dividend_yield)
          * spot_price
          * math.fwd_gradient(dcdk_fn, spot_price)
          + dividend_yield * _option_price(time, spot_price)
      )
      denominator = (
          math.fwd_gradient(d2cdk2_fn, spot_price) * spot_price**2
      )
      # we use relu for safety so that we do not take the square root of
      # negative real `Tensors`.
      local_volatility_squared = tf.nn.relu(
          2 * tf.math.divide_no_nan(numerator, denominator)
      )
      return tf.math.sqrt(local_volatility_squared)
  
imports: import functools
  from typing import Any, Callable, List, Optional, Union
  import tensorflow.compat.v2
  from tf_quant_finance import black_scholes
  from tf_quant_finance import datetime
  from tf_quant_finance import math
  from tf_quant_finance import types
  from tf_quant_finance.experimental.pricing_platform.framework.market_data import volatility_surface
  from tf_quant_finance.math import interpolation
  from tf_quant_finance.math import piecewise
  from tf_quant_finance.math import random
  from tf_quant_finance.models import generic_ito_process
label_desc: Use image node_id 1 for calling a global function with example usage: _dupire_local_volatility_prices(time, spot_price, initial_spot_price, implied_volatility_surface, discount_factor_fn, dividend_yield) and returns: tf, c_k_t