candding 0.1.0

Pure candle embeddings for Rust with no ONNX: dense, sparse, multi-vector and rerank models today, image models on the roadmap
Documentation
use super::*;
use crate::models::rerank::flash_fixture;
use crate::models::rerank::flash_fixture::Numbering;
use crate::models::xlm_roberta_flash;
use crate::models::xlm_roberta_flash::PositionScheme;

fn load_flash(position_scheme: Option<PositionScheme>) -> Result<Box<dyn RerankModel>> {
  let vb = VarBuilder::from_tensors(flash_fixture::tensors(), DType::F32, &Device::Cpu);
  load_rerank(
    xlm_roberta_flash::ARCHITECTURE,
    &flash_fixture::config_json("absolute"),
    vb,
    RerankConventions {
      position_scheme,
      ..conventions(
        RerankHead::RobertaClassificationHead,
        ScoreActivation::Sigmoid,
      )
    },
  )
}

/// Both rows open with id 1, the pad id, so that position reads row `pad`, not `pad + 1`.
#[test]
fn load_rerank_hands_the_flash_encoder_its_position_scheme() {
  let model = load_flash(Some(PositionScheme::Absolute)).unwrap();
  let expected = ScoreActivation::Sigmoid
    .apply(flash_fixture::expected_logit(1, Numbering::FromPadPlusOne) as f32);
  for value in score(model.as_ref()) {
    assert!(
      (value - expected).abs() < 1e-6,
      "{value} against {expected}"
    );
  }
}

#[test]
fn load_rerank_refuses_a_flash_scheme_the_config_does_not_name() {
  for declared in [Some(PositionScheme::Rotary), None] {
    match load_flash(declared) {
      Err(CanddingError::PositionSchemeDisagreesWithConfig { config, .. }) => {
        assert_eq!(config, "absolute")
      }
      Ok(_) => panic!("{declared:?} against an absolute config must be refused"),
      Err(other) => panic!("{declared:?}: unexpected error: {other}"),
    }
  }
}