add qwen2.5vl model
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
use anyhow::Result;
|
||||
use candle_core::{DType, Device};
|
||||
|
||||
pub fn get_device(device: Option<&Device>) -> Device {
|
||||
match device {
|
||||
Some(d) => d.clone(),
|
||||
None => {
|
||||
#[cfg(feature = "cuda")]
|
||||
{
|
||||
Device::new_cuda(0).unwrap_or(Device::Cpu)
|
||||
}
|
||||
#[cfg(not(feature = "cuda"))]
|
||||
{
|
||||
Device::Cpu
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_dtype(dtype: Option<DType>, cfg_dtype: &str) -> DType {
|
||||
match dtype {
|
||||
Some(d) => d,
|
||||
None => {
|
||||
#[cfg(feature = "cuda")]
|
||||
{
|
||||
match cfg_dtype {
|
||||
"float32" | "float" => DType::F32,
|
||||
"float64" | "double" => DType::F64,
|
||||
"float16" => DType::F16,
|
||||
"bfloat16" => DType::BF16,
|
||||
"uint8" => DType::U8,
|
||||
"int8" | "int16" | "int32" | "int64" => DType::I64,
|
||||
_ => DType::F32,
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "cuda"))]
|
||||
{
|
||||
match cfg_dtype {
|
||||
"float32" | "float" => DType::F32,
|
||||
"float64" | "double" => DType::F64,
|
||||
"float16" | "bfloat16" => DType::F16, // cpu上bfloat16有问题
|
||||
"uint8" => DType::U8,
|
||||
"int8" | "int16" | "int32" | "int64" => DType::I64,
|
||||
_ => DType::F32,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn string_to_static_str(s: String) -> &'static str {
|
||||
Box::leak(s.into_boxed_str())
|
||||
}
|
||||
|
||||
pub fn find_safetensors_files(path: &str) -> Result<Vec<String>> {
|
||||
let mut files = Vec::new();
|
||||
|
||||
for entry in std::fs::read_dir(path)? {
|
||||
let entry = entry?;
|
||||
let file_path = entry.path();
|
||||
|
||||
if file_path.is_file() {
|
||||
if let Some(extension) = file_path.extension() {
|
||||
if extension == "safetensors" {
|
||||
files.push(file_path.to_string_lossy().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(files)
|
||||
}
|
||||
|
||||
pub fn round_by_factor(num: u32, factor: u32) -> u32 {
|
||||
let round = (num as f32 / factor as f32).round() as u32;
|
||||
round * factor
|
||||
}
|
||||
|
||||
pub fn floor_by_factor(num: f32, factor: u32) -> u32 {
|
||||
let floor = (num / factor as f32).floor() as u32;
|
||||
floor * factor
|
||||
}
|
||||
|
||||
pub fn ceil_by_factor(num: f32, factor: u32) -> u32 {
|
||||
let ceil = (num / factor as f32).ceil() as u32;
|
||||
ceil * factor
|
||||
}
|
||||
Reference in New Issue
Block a user