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
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[env]

RUST_LOG = "info,tower_http=debug,ort=warn,encoderfile=debug"

[patch.crates-io]
esaxx-rs = { git = "https://github.com/mozilla-ai/esaxx-rs-dyn-msvc.git" }
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions encoderfile/src/builder/base_binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ impl BaseBinaryResolver<'_> {

fn validate_binary(&self, path: &Path) -> Result<()> {
terminal::info("Validating binary...");
use std::os::unix::fs::PermissionsExt;

let meta = fs::metadata(path)
.with_context(|| format!("base binary missing at {}", path.display()))?;
Expand All @@ -114,9 +113,13 @@ impl BaseBinaryResolver<'_> {
anyhow::bail!("base binary is not a file: {}", path.display());
}

let mode = meta.permissions().mode();
if mode & 0o111 == 0 {
anyhow::bail!("base binary is not executable: {}", path.display());
#[cfg(not(target_os = "windows"))]
{
use std::os::unix::fs::PermissionsExt;
let mode = meta.permissions().mode();
if mode & 0o111 == 0 {
anyhow::bail!("base binary is not executable: {}", path.display());
}
}

terminal::success("Binary validated");
Expand Down
2 changes: 1 addition & 1 deletion encoderfile/src/builder/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl Transform {
match self {
Self::Path { path } => {
if !path.exists() {
bail!("No such file: {:?}", &path);
bail!("No such file: {:?}", path);
}

let mut code = String::new();
Expand Down
6 changes: 3 additions & 3 deletions encoderfile/src/builder/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn from_tokenizer(tokenizer: &Tokenizer) -> Result<TokenizerConfig> {

eprintln!(
"WARNING: No padding params found in `tokenizer.json`. Using defaults: {:?}",
&padding_params
padding_params
);

padding_params
Expand All @@ -130,8 +130,8 @@ fn from_tokenizer(tokenizer: &Tokenizer) -> Result<TokenizerConfig> {
let truncation_params = TruncationParams::default();

eprintln!(
"WARNING: No padding params found in `tokenizer.json`. Using defaults: {:?}",
&truncation_params,
"WARNING: No truncation params found in `tokenizer.json`. Using defaults: {:?}",
truncation_params
);

truncation_params
Expand Down
4 changes: 2 additions & 2 deletions encoderfile/src/transport/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ impl Commands {
let banner = crate::get_banner(state.model_id().as_str());

if disable_grpc && disable_http {
return Err(crate::error::ApiError::ConfigError(
Err(crate::error::ApiError::ConfigError(
"Cannot disable both gRPC and HTTP",
))?;
))?
}

match enable_otel {
Expand Down
2 changes: 1 addition & 1 deletion encoderfile/src/transport/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async fn serve_with_optional_tls<S: Inference>(
state: S,
into_service_fn: impl Fn(&S) -> IntoMakeServiceWithConnectInfo<axum::Router, SocketAddr>,
) -> Result<()> {
let addr = format!("{}:{}", &hostname, &port);
let addr = format!("{}:{}", hostname, port);

let router = into_service_fn(&state);

Expand Down
18 changes: 16 additions & 2 deletions encoderfile/tests/integration/test_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ tonic::include_proto!("encoderfile.metadata");

use encoderfile::generated::token_classification;

#[cfg(target_os = "windows")]
const BINARY_NAME: &str = "test.encoderfile.exe";

#[cfg(not(target_os = "windows"))]
const BINARY_NAME: &str = "test.encoderfile";

fn config(model_name: &String, model_path: &Path, output_path: &Path) -> String {
Expand Down Expand Up @@ -104,6 +108,11 @@ async fn test_build_encoderfile() -> Result<()> {
.status()
.expect("Failed to build encoderfile-runtime");

#[cfg(target_os = "windows")]
let base_binary_path = fs::canonicalize("../target/debug/encoderfile-runtime.exe")
.expect("Failed to canonicalize base binary path");

#[cfg(not(target_os = "windows"))]
let base_binary_path = fs::canonicalize("../target/debug/encoderfile-runtime")
.expect("Failed to canonicalize base binary path");

Expand Down Expand Up @@ -159,13 +168,18 @@ async fn test_build_encoderfile() -> Result<()> {
grpc_port,
)?;

println!("encoderfile spawned, waiting for it to become ready...");

wait_for_http(
format!("http://localhost:{http_port}/health").as_str(),
Duration::from_secs(10),
)
.await?;
println!("encoderfile is ready, sending inference requests...");
send_http_inference(&sample_text, http_port.to_string()).await?;
println!("http inference request successful");
send_grpc_inference(&sample_text, grpc_port.to_string()).await?;
println!("grpc inference request successful");

child.kill()?;
child.wait().ok();
Expand Down Expand Up @@ -212,7 +226,7 @@ async fn send_http_inference(sample_text: &str, http_port: String) -> Result<()>
}

async fn send_grpc_inference(sample_text: &str, grpc_port: String) -> Result<()> {
let mut client = token_classification::token_classification_inference_client::TokenClassificationInferenceClient::connect(format!("http://[::]:{grpc_port}/predict")).await?;
let mut client = token_classification::token_classification_inference_client::TokenClassificationInferenceClient::connect(format!("http://[::1]:{grpc_port}/predict")).await?;
let req = token_classification::TokenClassificationRequest {
inputs: vec![sample_text.to_owned()],
metadata: std::collections::HashMap::new(),
Expand All @@ -236,7 +250,7 @@ fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> anyhow::Result<
let src = src.as_ref();
let dst = dst.as_ref();

fs::create_dir_all(dst).context(format!("Failed to create directory {:?}", &dst))?;
fs::create_dir_all(dst).context(format!("Failed to create directory {:?}", dst))?;

for entry in fs::read_dir(src)? {
let entry = entry?;
Expand Down
2 changes: 1 addition & 1 deletion encoderfile/tests/integration/test_inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> anyhow::Result<
let src = src.as_ref();
let dst = dst.as_ref();

fs::create_dir_all(dst).context(format!("Failed to create directory {:?}", &dst))?;
fs::create_dir_all(dst).context(format!("Failed to create directory {:?}", dst))?;

for entry in fs::read_dir(src)? {
let entry = entry?;
Expand Down
3 changes: 3 additions & 0 deletions test_config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
encoderfile:
name: my-model-2
path: models/token_classification
base_binary_path: target/debug/encoderfile-runtime
# Base binary for windows
# base_binary_path: target/debug/encoderfile-runtime.exe
model_type: token_classification
output_path: ./test-model.encoderfile
transform: |
Expand Down
Loading