Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ jobs:
- name: Project setup
uses: ./.github/actions/project-setup

- name: Install test dependencies
run: make setup
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}

- name: Install llvm-tools-preview
run: rustup component add llvm-tools-preview

Expand Down Expand Up @@ -116,11 +111,6 @@ jobs:
with:
toolchain: nightly

- name: Install test dependencies
run: make setup
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}

- run: rustup component add --toolchain nightly-x86_64-unknown-linux-gnu clippy

- name: Run Clippy
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# cargo tarpaulin
*.profraw

models/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[codz]
Expand Down
2 changes: 1 addition & 1 deletion encoderfile/src/build_cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ mod tests {
let cfg = EncoderfileConfig {
name: "my-cool-model".into(),
version: "1.0".into(),
path: ModelPath::Directory("../models/embedding".into()),
path: ModelPath::Directory("../models/dummy_electra_token_embeddings".into()),
model_type: ModelType::Embedding,
output_path: Some(base.clone()),
cache_dir: Some(base.clone()),
Expand Down
12 changes: 11 additions & 1 deletion encoderfile/src/build_cli/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@ impl ModelTypeExt for crate::common::ModelType {
Self::Embedding => validate_embedding_model(model),
Self::SequenceClassification => validate_sequence_classification_model(model),
Self::TokenClassification => validate_token_classification_model(model),
Self::SentenceEmbedding => validate_embedding_model(model),
Self::SentenceEmbedding => validate_sentence_embedding_model(model),
}?;

PlannedAsset::from_asset_source(AssetSource::File(path), AssetKind::ModelWeights)
}
}

fn validate_sentence_embedding_model(model: Session) -> Result<()> {
let shape = get_outp_dim(model.outputs.as_slice(), "last_hidden_state")?;

if shape.len() != 2 {
bail!("Model must return tensor of shape [batch_size, n_labels]")
}

Ok(())
}

fn validate_embedding_model(model: Session) -> Result<()> {
let shape = get_outp_dim(model.outputs.as_slice(), "last_hidden_state")?;

Expand Down
6 changes: 3 additions & 3 deletions encoderfile/src/build_cli/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ mod tests {
let config = EncoderfileConfig {
name: "my-model".into(),
version: "0.0.1".into(),
path: ModelPath::Directory("../models/embedding".into()),
path: ModelPath::Directory("../models/dummy_electra_token_embeddings".into()),
model_type: ModelType::Embedding,
output_path: None,
cache_dir: None,
Expand Down Expand Up @@ -296,7 +296,7 @@ mod tests {
let config = EncoderfileConfig {
name: "my-model".into(),
version: "0.0.1".into(),
path: ModelPath::Directory("../models/embedding".into()),
path: ModelPath::Directory("../models/dummy_electra_token_embeddings".into()),
model_type: ModelType::Embedding,
output_path: None,
cache_dir: None,
Expand Down Expand Up @@ -334,7 +334,7 @@ mod tests {

#[test]
fn test_validate_tokenizer_no_config() {
let path = ModelPath::Directory("../models/dummy_token_classifier".into());
let path = ModelPath::Directory("../models/dummy_electra_token_classifier".into());

let explicit_path = ModelPath::Paths {
model_config_path: path.model_config_path().unwrap(),
Expand Down
7 changes: 5 additions & 2 deletions encoderfile/src/build_cli/transforms/validation/embedding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ mod tests {
EncoderfileConfig {
name: "my-model".to_string(),
version: "0.0.1".to_string(),
path: ModelPath::Directory(std::path::PathBuf::from("models/embedding")),
path: ModelPath::Directory(std::path::PathBuf::from(
"models/dummy_electra_token_embeddings",
)),
model_type: ModelType::Embedding,
cache_dir: None,
output_path: None,
Expand All @@ -77,7 +79,8 @@ mod tests {
}

fn test_model_config() -> ModelConfig {
let config_json = include_str!("../../../../../models/embedding/config.json");
let config_json =
include_str!("../../../../../models/dummy_electra_token_embeddings/config.json");

serde_json::from_str(config_json).unwrap()
}
Expand Down
15 changes: 10 additions & 5 deletions encoderfile/src/build_cli/transforms/validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ mod tests {
EncoderfileConfig {
name: "my-model".to_string(),
version: "0.0.1".to_string(),
path: ModelPath::Directory(std::path::PathBuf::from("models/embedding")),
path: ModelPath::Directory(std::path::PathBuf::from(
"models/dummy_electra_token_embeddings",
)),
model_type: ModelType::Embedding,
cache_dir: None,
output_path: None,
Expand All @@ -124,7 +126,8 @@ mod tests {
}

fn test_model_config() -> ModelConfig {
let config_json = include_str!("../../../../../models/embedding/config.json");
let config_json =
include_str!("../../../../../models/dummy_electra_token_embeddings/config.json");

serde_json::from_str(config_json).unwrap()
}
Expand Down Expand Up @@ -156,7 +159,9 @@ mod tests {
let encoderfile_config = EncoderfileConfig {
name: "my-model".to_string(),
version: "0.0.1".to_string(),
path: ModelPath::Directory(std::path::PathBuf::from("models/embedding")),
path: ModelPath::Directory(std::path::PathBuf::from(
"models/dummy_electra_token_embeddings",
)),
model_type: ModelType::Embedding,
cache_dir: None,
output_path: None,
Expand All @@ -169,7 +174,7 @@ mod tests {

let model_config_str = include_str!(concat!(
"../../../../../models/",
"embedding",
"dummy_electra_token_embeddings",
"/config.json"
));

Expand Down Expand Up @@ -197,7 +202,7 @@ mod tests {

let model_config_str = include_str!(concat!(
"../../../../../models/",
"embedding",
"dummy_electra_token_embeddings",
"/config.json"
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ mod tests {
EncoderfileConfig {
name: "my-model".to_string(),
version: "0.0.1".to_string(),
path: ModelPath::Directory(std::path::PathBuf::from("models/embedding")),
path: ModelPath::Directory(std::path::PathBuf::from(
"models/dummy_electra_sequence_embeddings",
)),
model_type: ModelType::SentenceEmbedding,
cache_dir: None,
output_path: None,
Expand All @@ -80,7 +82,8 @@ mod tests {
}

fn test_model_config() -> ModelConfig {
let config_json = include_str!("../../../../../models/embedding/config.json");
let config_json =
include_str!("../../../../../models/dummy_electra_sequence_embeddings/config.json");

serde_json::from_str(config_json).unwrap()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mod tests {

fn test_model_config() -> ModelConfig {
let config_json =
include_str!("../../../../../models/dummy_sequence_classifier/config.json");
include_str!("../../../../../models/dummy_electra_sequence_classifier/config.json");

serde_json::from_str(config_json).unwrap()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ mod tests {
}

fn test_model_config() -> ModelConfig {
let config_json = include_str!("../../../../../models/dummy_token_classifier/config.json");
let config_json =
include_str!("../../../../../models/dummy_electra_token_classifier/config.json");

serde_json::from_str(config_json).unwrap()
}
Expand Down
6 changes: 3 additions & 3 deletions encoderfile/src/dev_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use parking_lot::Mutex;
use std::str::FromStr;
use std::{fs::File, io::BufReader};

const EMBEDDING_DIR: &str = "../models/embedding";
const SEQUENCE_CLASSIFICATION_DIR: &str = "../models/sequence_classification";
const TOKEN_CLASSIFICATION_DIR: &str = "../models/token_classification";
const EMBEDDING_DIR: &str = "../models/dummy_electra_token_embeddings";
const SEQUENCE_CLASSIFICATION_DIR: &str = "../models/dummy_electra_sequence_classifier";
const TOKEN_CLASSIFICATION_DIR: &str = "../models/dummy_electra_token_classifier";

pub fn get_state<T: ModelTypeSpec>(dir: &str) -> AppState<T> {
let config = Config {
Expand Down
4 changes: 2 additions & 2 deletions encoderfile/tests/integration/test_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ encoderfile:
)
}

const MODEL_ASSETS_PATH: &str = "../models/dummy_token_classifier";
const MODEL_ASSETS_PATH: &str = "../models/dummy_electra_token_classifier";

#[tokio::test]
async fn test_build_encoderfile() -> Result<()> {
Expand All @@ -56,7 +56,7 @@ async fn test_build_encoderfile() -> Result<()> {
.canonicalize()
.expect("Failed to canonicalize temp path");

let tmp_model_path = path.join("models").join("dummy_token_classifier");
let tmp_model_path = path.join("models").join("dummy_electra_token_classifier");

let ef_config_path = path.join("encoderfile.yml");
let encoderfile_path = path.join(BINARY_NAME);
Expand Down
4 changes: 2 additions & 2 deletions encoderfile/tests/integration/test_inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ encoderfile:
)
}

const MODEL_ASSETS_PATH: &str = "../models/token_classification";
const MODEL_ASSETS_PATH: &str = "../models/dummy_electra_token_classifier";

#[test]
fn test_inspect_encoderfile() -> Result<()> {
Expand All @@ -48,7 +48,7 @@ fn test_inspect_encoderfile() -> Result<()> {
.canonicalize()
.expect("Failed to canonicalize temp path");

let tmp_model_path = path.join("models").join("token_classification");
let tmp_model_path = path.join("models").join("dummy_electra_token_classifier");

let ef_config_path = path.join("encoderfile.yml");
let encoderfile_path = path.join(BINARY_NAME);
Expand Down
2 changes: 2 additions & 0 deletions encoderfile/tests/test_grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ macro_rules! test_grpc_service {
.unwrap()
.into_inner();

println!("Model metadata: {:?}", response);

if $has_labels {
assert!(!response.id2label.is_empty(), "id2label is an empty dict")
} else {
Expand Down
36 changes: 15 additions & 21 deletions encoderfile/tests/test_model_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,44 @@ use encoderfile::{build_cli::model::ModelTypeExt as _, common::ModelType};

#[test]
pub fn test_embedding() {
let path = PathBuf::from("../models/embedding/model.onnx");
let path = PathBuf::from("../models/dummy_electra_token_embeddings/model.onnx");

assert!(ModelType::Embedding.validate_model(&path).is_ok());
assert!(
ModelType::SequenceClassification
.validate_model(&path)
.is_err()
);
assert!(
ModelType::TokenClassification
.validate_model(&path)
.is_err()
);
assert!(ModelType::SentenceEmbedding.validate_model(&path).is_ok())
}

#[test]
pub fn test_sequence_classification() {
let path = PathBuf::from("../models/dummy_sequence_classifier/model.onnx");
pub fn test_token_classification() {
let path = PathBuf::from("../models/dummy_electra_token_classifier/model.onnx");

assert!(ModelType::Embedding.validate_model(&path).is_err());
assert!(ModelType::TokenClassification.validate_model(&path).is_ok());
}

#[test]
pub fn test_sequence_embeddings() {
let path = PathBuf::from("../models/dummy_electra_sequence_embeddings/model.onnx");

assert!(ModelType::SentenceEmbedding.validate_model(&path).is_ok());
assert!(
ModelType::SequenceClassification
.validate_model(&path)
.is_ok()
);
assert!(
ModelType::TokenClassification
.validate_model(&path)
.is_err()
);
assert!(ModelType::SentenceEmbedding.validate_model(&path).is_err())
}

#[test]
pub fn test_token_classification() {
let path = PathBuf::from("../models/dummy_token_classifier/model.onnx");
pub fn test_sequence_classification() {
let path = PathBuf::from("../models/dummy_electra_sequence_classifier/model.onnx");

assert!(ModelType::Embedding.validate_model(&path).is_err());
assert!(ModelType::SentenceEmbedding.validate_model(&path).is_err());
assert!(
ModelType::SequenceClassification
.validate_model(&path)
.is_err()
.is_ok()
);
assert!(ModelType::TokenClassification.validate_model(&path).is_ok());
assert!(ModelType::SentenceEmbedding.validate_model(&path).is_err())
}
47 changes: 47 additions & 0 deletions models/dummy_electra_sequence_classifier/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"architectures": [
"DummySequenceClassifier"
],
"attention_probs_dropout_prob": 0.1,
"classifier_dropout": null,
"embedding_size": 128,
"hidden_act": "gelu",
"hidden_dropout_prob": 0.1,
"hidden_size": 256,
"id2label": {
"0": "LABEL_0",
"1": "LABEL_1",
"2": "LABEL_2",
"3": "LABEL_3",
"4": "LABEL_4",
"5": "LABEL_5",
"6": "LABEL_6"
},
"initializer_range": 0.02,
"intermediate_size": 1024,
"label2id": {
"LABEL_0": 0,
"LABEL_1": 1,
"LABEL_2": 2,
"LABEL_3": 3,
"LABEL_4": 4,
"LABEL_5": 5,
"LABEL_6": 6
},
"layer_norm_eps": 1e-12,
"max_position_embeddings": 512,
"model_type": "mozilla-ai/test-dummy-sequence-classifier",
"num_attention_heads": 4,
"num_hidden_layers": 12,
"pad_token_id": 0,
"position_embedding_type": "absolute",
"summary_activation": "gelu",
"summary_last_dropout": 0.1,
"summary_type": "first",
"summary_use_proj": true,
"torch_dtype": "float32",
"transformers_version": "4.55.4",
"type_vocab_size": 2,
"use_cache": true,
"vocab_size": 30522
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"cls_token": "[CLS]",
"mask_token": "[MASK]",
"pad_token": "[PAD]",
"sep_token": "[SEP]",
"unk_token": "[UNK]"
}
Loading