[Rust Frontend] Strongly type wire dtypes and multimodal modalities (#56174)
Co-authored-by: Codex <noreply@openai.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Signed-off-by: Bugen Zhao <i@bugenzhao.com>
This commit is contained in:
co-authored by
Codex
mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent
285cbce6bd
commit
41cffa9af0
@@ -60,30 +60,9 @@ pub struct MultimodalModelInfo {
|
||||
/// Per-modality item-count limits configured by `--limit-mm-per-prompt`.
|
||||
///
|
||||
/// Modalities absent from the map are unlimited.
|
||||
pub type MmLimitPerPrompt = HashMap<MmLimitModality, MmLimitSpec>;
|
||||
pub type MmLimitPerPrompt = HashMap<MmModality, MmLimitSpec>;
|
||||
|
||||
/// Modalities that `--limit-mm-per-prompt` can be keyed by.
|
||||
///
|
||||
/// Closed on purpose: these are exactly the keys Python accepts, per
|
||||
/// `MultiModalDummyOptionsBuiltins` in `vllm/config/multimodal.py`.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum MmLimitModality {
|
||||
Image,
|
||||
Audio,
|
||||
Video,
|
||||
}
|
||||
|
||||
impl MmLimitModality {
|
||||
/// The wire name, matching Python's modality strings.
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Image => "image",
|
||||
Self::Audio => "audio",
|
||||
Self::Video => "video",
|
||||
}
|
||||
}
|
||||
}
|
||||
pub use vllm_engine_core_client::protocol::multimodal::MmModality;
|
||||
|
||||
/// One modality's limit, in either of the two shapes Python accepts.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@@ -646,17 +625,17 @@ fn input_audio_data_url(data: &str, format: Option<&str>) -> Result<String> {
|
||||
/// Embedding inputs share their base modality's budget rather than getting one
|
||||
/// of their own, matching Python's `modality.replace("_embeds", "")` in
|
||||
/// `vllm/entrypoints/chat_utils.py`.
|
||||
fn media_part_limit_modality(part: &MediaContentPart) -> Option<MmLimitModality> {
|
||||
fn media_part_limit_modality(part: &MediaContentPart) -> Option<MmModality> {
|
||||
match part {
|
||||
MediaContentPart::Text { .. } => None,
|
||||
MediaContentPart::ImageUrl { .. }
|
||||
| MediaContentPart::ImageData { .. }
|
||||
| MediaContentPart::ImageEmbeds { .. } => Some(MmLimitModality::Image),
|
||||
| MediaContentPart::ImageEmbeds { .. } => Some(MmModality::Image),
|
||||
MediaContentPart::AudioUrl { .. } | MediaContentPart::AudioData { .. } => {
|
||||
Some(MmLimitModality::Audio)
|
||||
Some(MmModality::Audio)
|
||||
}
|
||||
MediaContentPart::VideoUrl { .. } | MediaContentPart::VideoData { .. } => {
|
||||
Some(MmLimitModality::Video)
|
||||
Some(MmModality::Video)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -667,7 +646,7 @@ impl MultimodalModelInfo {
|
||||
///
|
||||
/// Modalities without a configured count are unlimited.
|
||||
fn validate_mm_limits(&self, media_parts: &[MediaContentPart]) -> Result<()> {
|
||||
let mut counts: HashMap<MmLimitModality, usize> = HashMap::new();
|
||||
let mut counts: HashMap<MmModality, usize> = HashMap::new();
|
||||
for part in media_parts {
|
||||
if let Some(modality) = media_part_limit_modality(part) {
|
||||
*counts.entry(modality).or_default() += 1;
|
||||
@@ -738,7 +717,11 @@ impl MultimodalModelInfo {
|
||||
for (item, range) in izip!(media.items, media_ranges) {
|
||||
features.push(MmFeatureSpec {
|
||||
data: Some(item.data),
|
||||
modality: media.modality.to_string(),
|
||||
modality: match media.modality {
|
||||
Modality::Image | Modality::ImageEmbeds => MmModality::Image,
|
||||
Modality::Video => MmModality::Video,
|
||||
Modality::Audio => MmModality::Audio,
|
||||
},
|
||||
identifier: item.uuid.unwrap_or_else(|| item.hash.clone()),
|
||||
mm_position: range,
|
||||
mm_hash: Some(item.hash),
|
||||
@@ -1029,10 +1012,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn validate_mm_limits_enforces_configured_limit_at_the_boundary() {
|
||||
let info = qwen3_vl_info_with_limits(HashMap::from([(
|
||||
MmLimitModality::Image,
|
||||
MmLimitSpec::Count(1),
|
||||
)]));
|
||||
let info =
|
||||
qwen3_vl_info_with_limits(HashMap::from([(MmModality::Image, MmLimitSpec::Count(1))]));
|
||||
assert!(info.validate_mm_limits(&[image_url_part()]).is_ok());
|
||||
|
||||
let error = info.validate_mm_limits(&[image_url_part(), image_url_part()]).unwrap_err();
|
||||
@@ -1047,10 +1028,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn validate_mm_limits_counts_image_embeds_against_the_image_limit() {
|
||||
let info = qwen3_vl_info_with_limits(HashMap::from([(
|
||||
MmLimitModality::Image,
|
||||
MmLimitSpec::Count(1),
|
||||
)]));
|
||||
let info =
|
||||
qwen3_vl_info_with_limits(HashMap::from([(MmModality::Image, MmLimitSpec::Count(1))]));
|
||||
let image_embeds_part = MediaContentPart::ImageEmbeds {
|
||||
payload: serde_json::Value::String("AAAA".to_string()),
|
||||
uuid: None,
|
||||
@@ -1068,7 +1047,7 @@ mod tests {
|
||||
#[test]
|
||||
fn validate_mm_limits_treats_a_count_less_options_object_as_unlimited() {
|
||||
let info = qwen3_vl_info_with_limits(HashMap::from([(
|
||||
MmLimitModality::Image,
|
||||
MmModality::Image,
|
||||
MmLimitSpec::Options {
|
||||
count: None,
|
||||
extra: BTreeMap::from([("width".to_string(), serde_json::json!(512))]),
|
||||
@@ -1086,9 +1065,9 @@ mod tests {
|
||||
fn limit_map_parses_both_shapes_python_accepts() {
|
||||
let limits = parse_limits(r#"{"image": 16, "video": {"count": 1, "num_frames": 32}}"#);
|
||||
|
||||
assert_eq!(limits[&MmLimitModality::Image].count(), Some(16));
|
||||
assert_eq!(limits[&MmLimitModality::Video].count(), Some(1));
|
||||
assert_eq!(limits.get(&MmLimitModality::Audio), None);
|
||||
assert_eq!(limits[&MmModality::Image].count(), Some(16));
|
||||
assert_eq!(limits[&MmModality::Video].count(), Some(1));
|
||||
assert_eq!(limits.get(&MmModality::Audio), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -268,14 +268,14 @@ mod tests {
|
||||
assert!(matches!(
|
||||
features.data.as_ref(),
|
||||
Some(MmKwargValue::Tensor(tensor))
|
||||
if tensor.dtype == "float32" && tensor.shape.first() == Some(&128)
|
||||
if tensor.dtype.as_str() == "float32" && tensor.shape.first() == Some(&128)
|
||||
));
|
||||
let lengths = &item.data["audio_feature_lengths"];
|
||||
assert!(matches!(&lengths.field, MmField::Batched(_)));
|
||||
assert!(matches!(
|
||||
lengths.data.as_ref(),
|
||||
Some(MmKwargValue::Tensor(tensor))
|
||||
if tensor.dtype == "int64" && tensor.shape.is_empty()
|
||||
if tensor.dtype.as_str() == "int64" && tensor.shape.is_empty()
|
||||
));
|
||||
}
|
||||
|
||||
@@ -314,14 +314,14 @@ mod tests {
|
||||
assert!(matches!(
|
||||
features.data.as_ref(),
|
||||
Some(MmKwargValue::Tensor(tensor))
|
||||
if tensor.dtype == "float32" && tensor.shape.get(1) == Some(&80)
|
||||
if tensor.dtype.as_str() == "float32" && tensor.shape.get(1) == Some(&80)
|
||||
));
|
||||
let count = &item.data["num_audio_tokens"];
|
||||
assert!(matches!(&count.field, MmField::Batched(_)));
|
||||
assert!(matches!(
|
||||
count.data.as_ref(),
|
||||
Some(MmKwargValue::Tensor(tensor))
|
||||
if tensor.dtype == "int64" && tensor.shape.is_empty()
|
||||
if tensor.dtype.as_str() == "int64" && tensor.shape.is_empty()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ mod tests {
|
||||
|
||||
fn assert_bool_mask(range: &PlaceholderRange, expected: &[bool]) {
|
||||
let tensor = range.is_embed.as_ref().expect("is_embed mask");
|
||||
assert_eq!(tensor.dtype, "bool");
|
||||
assert_eq!(tensor.dtype.as_str(), "bool");
|
||||
assert_eq!(tensor.shape, vec![expected.len()]);
|
||||
assert_eq!(
|
||||
tensor.data,
|
||||
|
||||
@@ -7,54 +7,17 @@ use std::mem::size_of;
|
||||
use half::{bf16, f16};
|
||||
use llm_multimodal::{ModelSpecificValue, PreprocessedEncoderInputs};
|
||||
use ndarray::ArrayD;
|
||||
use vllm_engine_core_client::protocol::dtype::ModelDtype;
|
||||
use vllm_engine_core_client::protocol::dtype::{ModelDtype, TensorDtype};
|
||||
use vllm_engine_core_client::protocol::multimodal::MmKwargValue as ProtocolKwargValue;
|
||||
use vllm_engine_core_client::protocol::tensor::{ShapeExt as _, WireArrayData, WireTensor};
|
||||
use vllm_engine_core_client::protocol::tensor::{WireArrayData, WireTensor};
|
||||
|
||||
use crate::error::{Error, Result, bail_multimodal, multimodal};
|
||||
|
||||
/// Element type retained alongside an encoded tensor during multimodal lowering.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub(super) enum TensorKind {
|
||||
/// 32-bit floating point.
|
||||
F32,
|
||||
/// IEEE 16-bit floating point.
|
||||
F16,
|
||||
/// Brain floating point.
|
||||
Bf16,
|
||||
/// Signed 64-bit integer.
|
||||
I64,
|
||||
/// Unsigned 32-bit integer.
|
||||
U32,
|
||||
}
|
||||
|
||||
impl TensorKind {
|
||||
const fn element_size(self) -> usize {
|
||||
match self {
|
||||
Self::F32 => size_of::<f32>(),
|
||||
Self::F16 => size_of::<f16>(),
|
||||
Self::Bf16 => size_of::<bf16>(),
|
||||
Self::I64 => size_of::<i64>(),
|
||||
Self::U32 => size_of::<u32>(),
|
||||
}
|
||||
}
|
||||
|
||||
const fn wire_dtype(self) -> &'static str {
|
||||
match self {
|
||||
Self::F32 => "float32",
|
||||
Self::F16 => "float16",
|
||||
Self::Bf16 => "bfloat16",
|
||||
Self::I64 => "int64",
|
||||
Self::U32 => "uint32",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Representation for multimodal kwarg values for transformation.
|
||||
#[derive(Debug)]
|
||||
pub(super) enum KwargValue {
|
||||
/// Tensor with row-major flat data and shape.
|
||||
Tensor { kind: TensorKind, wire: WireTensor },
|
||||
Tensor { wire: WireTensor },
|
||||
/// Non-tensor kwarg value that is shared or copied as-is.
|
||||
Passthrough(ProtocolKwargValue),
|
||||
}
|
||||
@@ -96,11 +59,11 @@ impl KwargValue {
|
||||
}
|
||||
ModelSpecificValue::IntTensor { data, shape } => {
|
||||
let wire = WireTensor::from_i64(shape, data).map_err(Error::Multimodal)?;
|
||||
Self::tensor(TensorKind::I64, wire)
|
||||
Self::Tensor { wire }
|
||||
}
|
||||
ModelSpecificValue::UintTensor { data, shape } => {
|
||||
let wire = WireTensor::from_u32(shape, data).map_err(Error::Multimodal)?;
|
||||
Self::tensor(TensorKind::U32, wire)
|
||||
Self::Tensor { wire }
|
||||
}
|
||||
ModelSpecificValue::Int(value) => Self::Passthrough(Int(value)),
|
||||
ModelSpecificValue::Float(value) => Self::Passthrough(Float(value)),
|
||||
@@ -148,23 +111,16 @@ impl KwargValue {
|
||||
/// Convert a float tensor to the target float dtype if needed, keeping the
|
||||
/// same shape.
|
||||
fn from_f32_parts(data: Vec<f32>, shape: Vec<usize>, float_dtype: ModelDtype) -> Result<Self> {
|
||||
let (kind, wire) = match float_dtype {
|
||||
ModelDtype::Float16 => (
|
||||
TensorKind::F16,
|
||||
WireTensor::from_f16(shape, data.into_iter().map(f16::from_f32).collect()),
|
||||
),
|
||||
ModelDtype::BFloat16 => (
|
||||
TensorKind::Bf16,
|
||||
WireTensor::from_bf16(shape, data.into_iter().map(bf16::from_f32).collect()),
|
||||
),
|
||||
ModelDtype::Float32 => (TensorKind::F32, WireTensor::from_f32(shape, data)),
|
||||
let wire = match float_dtype {
|
||||
ModelDtype::Float16 => {
|
||||
WireTensor::from_f16(shape, data.into_iter().map(f16::from_f32).collect())
|
||||
}
|
||||
ModelDtype::BFloat16 => {
|
||||
WireTensor::from_bf16(shape, data.into_iter().map(bf16::from_f32).collect())
|
||||
}
|
||||
ModelDtype::Float32 => WireTensor::from_f32(shape, data),
|
||||
};
|
||||
wire.map(|wire| Self::tensor(kind, wire)).map_err(Error::Multimodal)
|
||||
}
|
||||
|
||||
fn tensor(kind: TensorKind, wire: WireTensor) -> Self {
|
||||
debug_assert_eq!(wire.dtype, kind.wire_dtype());
|
||||
Self::Tensor { kind, wire }
|
||||
wire.map(|wire| Self::Tensor { wire }).map_err(Error::Multimodal)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,9 +171,7 @@ impl KwargValue {
|
||||
drop_axis: bool,
|
||||
) -> Result<ProtocolKwargValue> {
|
||||
let wire = match self {
|
||||
Self::Tensor { kind, wire } => {
|
||||
slice_first_axis_range(wire, kind.element_size(), start, end, drop_axis)
|
||||
}
|
||||
Self::Tensor { wire } => slice_first_axis_range(wire, start, end, drop_axis),
|
||||
Self::Passthrough(value) => return Ok(value.clone()),
|
||||
};
|
||||
wire.map(ProtocolKwargValue::Tensor)
|
||||
@@ -244,10 +198,7 @@ pub(super) fn flat_range_for_index(
|
||||
/// Read a tensor value as per-image sizes for flat slicing.
|
||||
fn tensor_as_usize_vec(tensor: &KwargValue) -> Result<Vec<usize>> {
|
||||
match tensor {
|
||||
KwargValue::Tensor {
|
||||
kind: TensorKind::I64,
|
||||
wire,
|
||||
} => raw_tensor_bytes(wire, size_of::<i64>())?
|
||||
KwargValue::Tensor { wire } if wire.dtype == TensorDtype::I64 => raw_tensor_bytes(wire)?
|
||||
.chunks_exact(size_of::<i64>())
|
||||
.map(|bytes| i64::from_ne_bytes(bytes.try_into().expect("exact int64 chunk")))
|
||||
.map(|value| {
|
||||
@@ -255,13 +206,14 @@ fn tensor_as_usize_vec(tensor: &KwargValue) -> Result<Vec<usize>> {
|
||||
.map_err(|_| multimodal!("negative flat tensor size `{value}`"))
|
||||
})
|
||||
.collect(),
|
||||
KwargValue::Tensor {
|
||||
kind: TensorKind::U32,
|
||||
wire,
|
||||
} => Ok(raw_tensor_bytes(wire, size_of::<u32>())?
|
||||
.chunks_exact(size_of::<u32>())
|
||||
.map(|bytes| u32::from_ne_bytes(bytes.try_into().expect("exact uint32 chunk")) as usize)
|
||||
.collect()),
|
||||
KwargValue::Tensor { wire } if wire.dtype == TensorDtype::U32 => {
|
||||
Ok(raw_tensor_bytes(wire)?
|
||||
.chunks_exact(size_of::<u32>())
|
||||
.map(|bytes| {
|
||||
u32::from_ne_bytes(bytes.try_into().expect("exact uint32 chunk")) as usize
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
_ => Err(multimodal!("flat tensor sizes must be int64 or uint32")),
|
||||
}
|
||||
}
|
||||
@@ -269,13 +221,13 @@ fn tensor_as_usize_vec(tensor: &KwargValue) -> Result<Vec<usize>> {
|
||||
/// Slice a flat row-major tensor along its first axis.
|
||||
fn slice_first_axis_range(
|
||||
tensor: &WireTensor,
|
||||
element_size: usize,
|
||||
start: usize,
|
||||
end: usize,
|
||||
drop_axis: bool,
|
||||
) -> Result<WireTensor> {
|
||||
let shape = tensor.shape.as_slice();
|
||||
raw_tensor_bytes(tensor, element_size)?;
|
||||
raw_tensor_bytes(tensor)?;
|
||||
let element_size = tensor.dtype.element_size();
|
||||
let first_dim = *shape.first().ok_or_else(|| multimodal!("tensor has no first dimension"))?;
|
||||
if start > end || end > first_dim {
|
||||
bail_multimodal!("invalid tensor slice {start}..{end} for first dimension {first_dim}");
|
||||
@@ -302,34 +254,15 @@ fn slice_first_axis_range(
|
||||
return Err(multimodal!("cannot slice an aux tensor buffer"));
|
||||
};
|
||||
Ok(WireTensor::from_raw_bytes(
|
||||
tensor.dtype.clone(),
|
||||
tensor.dtype,
|
||||
out_shape,
|
||||
data.slice(data_start..data_end),
|
||||
))
|
||||
}
|
||||
|
||||
fn raw_tensor_bytes(tensor: &WireTensor, element_size: usize) -> Result<&[u8]> {
|
||||
let WireArrayData::RawView(data) = &tensor.data else {
|
||||
return Err(multimodal!("expected an inline tensor buffer"));
|
||||
};
|
||||
let expected_bytes = tensor
|
||||
.shape
|
||||
.checked_numel()
|
||||
.and_then(|numel| numel.checked_mul(element_size))
|
||||
.ok_or_else(|| {
|
||||
multimodal!(
|
||||
"tensor shape {:?} byte length overflowed usize",
|
||||
tensor.shape
|
||||
)
|
||||
})?;
|
||||
if expected_bytes != data.len() {
|
||||
bail_multimodal!(
|
||||
"tensor shape {:?} expects {expected_bytes} bytes, got {}",
|
||||
tensor.shape,
|
||||
data.len()
|
||||
);
|
||||
}
|
||||
Ok(data)
|
||||
fn raw_tensor_bytes(tensor: &WireTensor) -> Result<&[u8]> {
|
||||
tensor.validate_inline().map_err(Error::Multimodal)?;
|
||||
Ok(tensor.data.as_raw_view().expect("validated inline tensor"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -373,7 +306,7 @@ mod tests {
|
||||
};
|
||||
|
||||
assert_eq!(tensor.shape, shape, "{name} layout shape");
|
||||
assert_eq!(tensor.dtype, "float32", "{name} layout dtype");
|
||||
assert_eq!(tensor.dtype.as_str(), "float32", "{name} layout dtype");
|
||||
assert_eq!(
|
||||
tensor.data.into_raw_view().unwrap(),
|
||||
expected,
|
||||
@@ -386,10 +319,9 @@ mod tests {
|
||||
fn batched_wire_value_at_drops_first_axis() {
|
||||
let data = vec![1.0_f32, 2.0, 3.0, 4.0];
|
||||
let expected_ptr = data.as_ptr().cast::<u8>().wrapping_add(2 * size_of::<f32>());
|
||||
let value = KwargValue::tensor(
|
||||
TensorKind::F32,
|
||||
WireTensor::from_f32(vec![2, 2], data).unwrap(),
|
||||
);
|
||||
let value = KwargValue::Tensor {
|
||||
wire: WireTensor::from_f32(vec![2, 2], data).unwrap(),
|
||||
};
|
||||
|
||||
let ProtocolKwargValue::Tensor(tensor) = value.batched_wire_value_at(1).unwrap() else {
|
||||
panic!("expected tensor");
|
||||
@@ -406,10 +338,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn flat_wire_value_range_keeps_first_axis() {
|
||||
let value = KwargValue::tensor(
|
||||
TensorKind::U32,
|
||||
WireTensor::from_u32(vec![5, 2], (0..10_u32).collect()).unwrap(),
|
||||
);
|
||||
let value = KwargValue::Tensor {
|
||||
wire: WireTensor::from_u32(vec![5, 2], (0..10_u32).collect()).unwrap(),
|
||||
};
|
||||
|
||||
let ProtocolKwargValue::Tensor(tensor) = value.flat_wire_value_range(1, 3).unwrap() else {
|
||||
panic!("expected tensor");
|
||||
@@ -424,10 +355,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn flat_range_for_index_uses_size_tensor() {
|
||||
let sizes = KwargValue::tensor(
|
||||
TensorKind::I64,
|
||||
WireTensor::from_i64(vec![3], vec![2_i64, 3, 4]).unwrap(),
|
||||
);
|
||||
let sizes = KwargValue::Tensor {
|
||||
wire: WireTensor::from_i64(vec![3], vec![2_i64, 3, 4]).unwrap(),
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
flat_range_for_index(&sizes, "image_grid_thw", 1).unwrap(),
|
||||
@@ -437,11 +367,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn slice_first_axis_range_errors_on_shape_data_mismatch() {
|
||||
let tensor = WireTensor::from_raw("float32", vec![2, 2], vec![0; 3 * size_of::<f32>()]);
|
||||
let error = slice_first_axis_range(&tensor, size_of::<f32>(), 0, 1, true).unwrap_err();
|
||||
let tensor =
|
||||
WireTensor::from_raw(TensorDtype::F32, vec![2, 2], vec![0; 3 * size_of::<f32>()]);
|
||||
let error = slice_first_axis_range(&tensor, 0, 1, true).unwrap_err();
|
||||
|
||||
assert!(
|
||||
matches!(error, Error::Multimodal(message) if message.contains("expects 16 bytes"))
|
||||
matches!(error, Error::Multimodal(message) if message.contains("does not match expected 16"))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -455,7 +386,7 @@ mod tests {
|
||||
panic!("expected tensor");
|
||||
};
|
||||
|
||||
assert_eq!(tensor.dtype, "bfloat16");
|
||||
assert_eq!(tensor.dtype.as_str(), "bfloat16");
|
||||
assert_eq!(tensor.shape, vec![2]);
|
||||
assert_eq!(tensor.data.into_raw_view().unwrap().len(), 4);
|
||||
}
|
||||
@@ -470,7 +401,7 @@ mod tests {
|
||||
panic!("expected tensor");
|
||||
};
|
||||
|
||||
assert_eq!(tensor.dtype, "float16");
|
||||
assert_eq!(tensor.dtype.as_str(), "float16");
|
||||
assert_eq!(tensor.shape, vec![2]);
|
||||
assert_eq!(tensor.data.into_raw_view().unwrap().len(), 4);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user