Skip to main content

BatchExec

Struct BatchExec 

Source
pub struct BatchExec<'c, 'g> { /* private fields */ }
Expand description

一次批量前向的执行器。一批一个,用完检查 BatchExec::finish。

Implementations§

Source§

impl<'c, 'g> BatchExec<'c, 'g>

Source

pub fn finish(&self) -> Result<(), String>

等已提交的工作跑完,报告这一批有没有出错。

Source

pub fn dry_usage(&self) -> (u64, u64)

试算的结果:(工作内存峰值, 还没上显存的权重),字节。真正执行时恒为 0。

Source

pub fn upload(&self, x: &Tensor) -> DevTensor<'c, 'g>

上传一个样本(批大小必须是 1),有效宽度就是实际宽度。

Source

pub fn placeholder(&self, shape: Vec<usize>) -> DevTensor<'c, 'g>

不带数据的张量(试算时当输入用);有效宽度取最后一维。

Source

pub fn upload_batch(&self, xs: &[&Tensor]) -> DevTensor<'c, 'g>

上传一批 [C, H, w_i](C、H 相同),右边补 0 到最宽的宽度,并记下各样本的有效宽度。

Source

pub fn download(&self, t: &DevTensor<'_, 'g>) -> Result<Vec<f32>, String>

下载整个批量张量(行优先,含补边);出错或试算时返回错误或空。

Trait Implementations§

Source§

impl Drop for BatchExec<'_, '_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<'c, 'g> Exec for BatchExec<'c, 'g>

Source§

type T = DevTensor<'c, 'g>

张量句柄。
Source§

fn shape(&self, x: &Self::T) -> Vec<usize>

单个样本的形状。
Source§

fn conv(&self, l: &Conv2d, x: &Self::T) -> Self::T

Source§

fn conv_transpose(&self, l: &ConvTranspose2d, x: &Self::T) -> Self::T

Source§

fn act(&self, a: Activation, x: &mut Self::T)

Source§

fn add(&self, a: &Self::T, b: &Self::T) -> Self::T

Source§

fn add_assign(&self, a: &mut Self::T, b: &Self::T)

Source§

fn pad_right_bottom(&self, x: &Self::T, right: usize, bottom: usize) -> Self::T

Source§

fn max_pool2d( &self, x: &Self::T, k: (usize, usize), stride: (usize, usize), ceil_mode: bool, ) -> Self::T

Source§

fn avg_pool2d(&self, x: &Self::T, k: (usize, usize)) -> Self::T

Source§

fn global_avg(&self, x: &Self::T) -> Self::T

每个通道的全局平均,结果 [C, 1, 1]。
Source§

fn scale_channels(&self, x: &mut Self::T, s: &Self::T)

s 是 [C, 1, 1],逐通道乘到 x 上。
Source§

fn se_gate(&self, s: &mut Self::T)

颈部 SE 的门:v ← 1 + clamp(0.2·v + 0.5, 0, 1)。
Source§

fn concat(&self, xs: &[&Self::T]) -> Self::T

Source§

fn upsample(&self, x: &Self::T, oh: usize, ow: usize) -> Self::T

最近邻插值到 oh × ow。
Source§

fn chw_to_seq(&self, x: &Self::T) -> Self::T

Source§

fn linear(&self, l: &Linear, x: &Self::T) -> Self::T

Source§

fn layer_norm(&self, l: &LayerNorm, x: &Self::T) -> Self::T

Source§

fn attention(&self, qkv: &Self::T, heads: usize) -> Self::T

多头自注意力的中段:输入线性层出来的 [T, 3C](列 = s·C + h·hd + d,s 为 0 = q、1 = k、2 = v), 返回拼回的 [T, C],分数按 head_dim^−0.5 缩放。
Source§

fn ctc_digest(&self, logits: &Self::T) -> Vec<Vec<(u32, f32)>>

CTC 摘要:每个样本一个列表,每步一个(最大类下标,softmax 的最大概率)。

Auto Trait Implementations§

§

impl<'c, 'g> !Freeze for BatchExec<'c, 'g>

§

impl<'c, 'g> !RefUnwindSafe for BatchExec<'c, 'g>

§

impl<'c, 'g> !Send for BatchExec<'c, 'g>

§

impl<'c, 'g> !Sync for BatchExec<'c, 'g>

§

impl<'c, 'g> !UnwindSafe for BatchExec<'c, 'g>

§

impl<'c, 'g> Forget for BatchExec<'c, 'g>

§

impl<'c, 'g> Unpin for BatchExec<'c, 'g>

§

impl<'c, 'g> UnsafeUnpin for BatchExec<'c, 'g>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.