104 lines
3.2 KiB
Rust
104 lines
3.2 KiB
Rust
//! Moved out of the parent module by STRA-338: fn minimum_part_payload_bytes, impl DerivedIdentity, impl
|
|
//! Drop_for_StagingDir, fn prepare_f32, fn prepare_iq3, fn prepare_mixed.
|
|
|
|
#[allow(unused_imports)]
|
|
use super::*;
|
|
|
|
pub(crate) fn minimum_part_payload_bytes(derived_bytes: u64, levels: u8) -> Result<u64, String> {
|
|
if !derived_bytes.is_multiple_of(4) || !(1..=8).contains(&levels) {
|
|
return Err("invalid KAR part F32 byte count or level".into());
|
|
}
|
|
let plane_bytes = (derived_bytes / 4)
|
|
.div_ceil(32)
|
|
.checked_mul(4 * u64::from(levels))
|
|
.ok_or("KAR minimum payload size overflow")?;
|
|
Ok(plane_bytes.min(derived_bytes))
|
|
}
|
|
|
|
impl DerivedIdentity {
|
|
pub(super) fn gguf_digest(&self) -> [u8; 32] {
|
|
match self {
|
|
Self::Iq3(identity) => identity.gguf_sha256,
|
|
Self::Mixed(identity) => identity.gguf_sha256,
|
|
}
|
|
}
|
|
|
|
pub(super) fn derived_digest(&self) -> [u8; 32] {
|
|
match self {
|
|
Self::Iq3(identity) => identity.derived_sha256,
|
|
Self::Mixed(identity) => identity.derived_sha256,
|
|
}
|
|
}
|
|
|
|
pub(super) fn derived_bytes(&self) -> u64 {
|
|
match self {
|
|
Self::Iq3(identity) => identity.derived_bytes,
|
|
Self::Mixed(identity) => identity.derived_bytes,
|
|
}
|
|
}
|
|
|
|
pub(super) fn tensor(&self, number: usize) -> DerivedTensorRef<'_> {
|
|
match self {
|
|
Self::Iq3(identity) => {
|
|
let tensor = &identity.tensors[number];
|
|
DerivedTensorRef {
|
|
name: &tensor.name,
|
|
source_kind: 21,
|
|
source_digest: &tensor.iq3_sha256,
|
|
f32_digest: &tensor.f32_sha256,
|
|
offset: tensor.derived_offset,
|
|
bytes: tensor.derived_bytes,
|
|
}
|
|
}
|
|
Self::Mixed(identity) => {
|
|
let tensor = &identity.tensors[number];
|
|
DerivedTensorRef {
|
|
name: &tensor.name,
|
|
source_kind: tensor.source_kind,
|
|
source_digest: &tensor.source_sha256,
|
|
f32_digest: &tensor.f32_sha256,
|
|
offset: tensor.derived_offset,
|
|
bytes: tensor.derived_bytes,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(super) fn tensor_count(&self) -> usize {
|
|
match self {
|
|
Self::Iq3(identity) => identity.tensors.len(),
|
|
Self::Mixed(identity) => identity.tensors.len(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Drop for StagingDir {
|
|
fn drop(&mut self) {
|
|
let _ = fs::remove_dir_all(&self.0);
|
|
}
|
|
}
|
|
|
|
pub fn prepare_f32(
|
|
source_path: &Path,
|
|
destination: &Path,
|
|
levels: u8,
|
|
) -> Result<PreviewSummary, String> {
|
|
prepare(source_path, destination, levels, PreviewKind::F32)
|
|
}
|
|
|
|
pub fn prepare_iq3(
|
|
source_path: &Path,
|
|
destination: &Path,
|
|
levels: u8,
|
|
) -> Result<PreviewSummary, String> {
|
|
prepare(source_path, destination, levels, PreviewKind::Iq3)
|
|
}
|
|
|
|
pub fn prepare_mixed(
|
|
source_path: &Path,
|
|
destination: &Path,
|
|
levels: u8,
|
|
) -> Result<PreviewSummary, String> {
|
|
prepare(source_path, destination, levels, PreviewKind::Mixed)
|
|
}
|