Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

NX Examples

nx.livemd

NX Examples

Mix.install(
  [
    {:kino_bumblebee, "~> 0.2.1"},
    {:exla, "~> 0.5.0"}
  ],
  config: [nx: [default_backend: EXLA.Backend]]
)
# Set environment variable
# EXLA_TARGET=cuda12

Section


  # Creates two tensors
  tensor1 = Nx.tensor([[1, 2], [3, 4]])
  tensor2 = Nx.tensor([[5, 6], [7, 8]])

  # Performs some basic operations
  sum = Nx.add(tensor1, tensor2)
  product = Nx.multiply(tensor1, tensor2)
  difference = Nx.subtract(tensor1, tensor2)

  {sum, product, difference}

19:11:44.816 [info] TfrtCpuClient created.
{#Nx.Tensor<
   s64[2][2]
   EXLA.Backend
   [
     [6, 8],
     [10, 12]
   ]
 >,
 #Nx.Tensor<
   s64[2][2]
   EXLA.Backend
   [
     [5, 12],
     [21, 32]
   ]
 >,
 #Nx.Tensor<
   s64[2][2]
   EXLA.Backend
   [
     [-4, -4],
     [-4, -4]
   ]
 >}