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

Computing Resource Allocation

computing-resource-allocation.livemd

Computing Resource Allocation

case :os.type() do
  {:unix, :darwin} ->
    Mix.install([
      {:nx, "~> 0.9.2"},
      {:emlx, github: "elixir-nx/emlx"},
      {:scholar, "~> 0.3.1"}
    ])
    
    Nx.default_backend({EMLX.Backend, device: :gpu})
    Nx.Defn.default_options(compiler: EMLX)

  {:unix, :linux} ->
    Mix.install([
      {:nx, "~> 0.9.2"},
      {:exla, "~> 0.9.2"},
      {:scholar, "~> 0.3.1"}
    ])

    Nx.global_default_backend(EXLA.Backend)
    Nx.Defn.default_options(compiler: EXLA, client: :cuda)
  
    Application.put_env(:exla, :clients, cuda: [platform: :cuda, memory_fraction: 0.2])  
end

Data Preparation

x = Nx.tensor([
  [0.005, 0.0074, 0.002, 1.0, 0.420, 0.822],
  [1, 0.5, 0.85, 1.0, 0.420, 0.822],
  [0.005, 0.0074, 0.002, 1.0, 0.20, 0.20]
])

y = Nx.tensor([1, 0, 0])

Train

model = Scholar.Linear.LogisticRegression.fit(x, y, num_classes: 2)

Predict

Scholar.Linear.LogisticRegression.predict_probability(model, Nx.tensor([[0.005, 0.0074, 0.002, 0.5, 0.18, 0.18]]))