Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: inference_fn changed from asynchronous to synchronous #7

Merged
merged 12 commits into from
Jul 26, 2023
Merged

Conversation

lazyky
Copy link
Contributor

@lazyky lazyky commented Jul 21, 2023

  • fix bugs
  • complete function test
  • delete the directory parameter in TaskConfig

Resove #1

- fix bugs
- complete function test
- delete the directory parameter in TaskConfig

Resove #1
Copy link
Owner

@bioinformatist bioinformatist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The design of the trait method inference should be improved to handle more flexible situations.

Copy link
Owner

@bioinformatist bioinformatist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go go go!

cml-core/src/core/inference.rs Outdated Show resolved Hide resolved
Copy link
Owner

@bioinformatist bioinformatist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test code for Inference trait needs to be changed.

@@ -149,6 +163,146 @@ mod tests {

#[tokio::test(flavor = "multi_thread")]
async fn test_concurrent_inference() -> Result<()> {
let cml = TDengine::from_dsn("taos://");
let taos = cml.build_sync()?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why connection by blocking here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my mistake

Comment on lines 280 to 294
tokio::spawn({
async move {
cml.inference(
batch_meta_1,
Field::new("output", Ty::Float, 8),
available_status,
&mut batch_data_1,
&pool,
inference_fn,
)
.await
.unwrap();
}
})
.await?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need more than one batch running simultaneously to validate if async works well.

cml-tdengine/src/core/register.rs Show resolved Hide resolved
Copy link
Owner

@bioinformatist bioinformatist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost done!

Comment on lines 305 to 327
let inference_data_fn = |inference_data, inference_model| {
if inference_data + inference_model > 25.0 {
Some(Value::Float(inference_data + model_inference))
} else {
None
}
};
for inference_data in vec_data.iter() {
let output = inference_data_fn(
fs::read_to_string(inference_data.data_path())
.unwrap()
.parse::<f32>()
.unwrap(),
model_inference,
);
result.push(
NewSampleBuilder::default()
.data_path(inference_data.data_path().to_path_buf())
.output(output)
.build()
.unwrap(),
);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for use a closure here, for the closure won't be used more than one time. Just move the calculations into loop, and use variables for staging intermediate results if necessary.

@bioinformatist bioinformatist merged commit 8dd10b3 into bioinformatist:main Jul 26, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants