pulsatrix
Loading...
Searching...
No Matches
bce_with_logits_loss.hpp
Go to the documentation of this file.
1
5#pragma once
6
9
10namespace pulsatrix {
11
51public:
56 explicit BCEWithLogitsLoss(DeviceBackend* backend);
57
71 [[nodiscard]] float forward(const Tensor& logits, const Tensor& target);
72
85 [[nodiscard]] Tensor backward() const;
86
87private:
88 DeviceBackend* backend_;
89 Tensor last_logits_;
90 Tensor last_target_;
91 bool has_forwarded_ = false;
92};
93
94} // namespace pulsatrix
loss = mean( max(x,0) - x*y + log(1 + exp(-|x|)) ), over all N*k elements of a (N,...
Definition bce_with_logits_loss.hpp:50
BCEWithLogitsLoss(DeviceBackend *backend)
Constructs a BCE-with-logits loss.
Tensor backward() const
Gradient w.r.t. the logits: grad[i] = (sigmoid(x[i]) - y[i]) / numel.
float forward(const Tensor &logits, const Tensor &target)
Computes the loss value and caches logits/target for backward().
Vendor-agnostic compute/memory backend. CPUBackend, CUDABackend (Phase 1.5), and HIPBackend (Phase 1....
Definition device_backend.hpp:219
N-dimensional tensor. Owns its data buffer exclusively; a DeviceBackend* is injected (not owned) – th...
Definition tensor.hpp:29
Abstract interface isolating vendor-specific memory/compute operations from Tensor/ComputationGraph.
Definition acquisition_functions.hpp:16
N-dimensional tensor – owns a buffer via DeviceBackend*, RAII (Rule of Five).