-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
- fix bugs - complete function test - delete the directory parameter in TaskConfig Resove #1
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go go go!
There was a problem hiding this 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.
cml-tdengine/src/core/inference.rs
Outdated
@@ -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()?; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my mistake
cml-tdengine/src/core/inference.rs
Outdated
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?; |
There was a problem hiding this comment.
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.
correct inference test_concurrent_inference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost done!
cml-tdengine/src/core/inference.rs
Outdated
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(), | ||
); | ||
} |
There was a problem hiding this comment.
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.
Resove #1