fix(ml): pad remaining state tensor paths for tensor core alignment
Additional padding in get_q_values and convert_to_state — these are currently unused in the training pipeline but would crash if called. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1264,7 +1264,16 @@ impl DQNTrainer {
|
||||
async fn get_q_values(&self, state: &TradingState) -> Result<Vec<f64>> {
|
||||
let agent = self.agent.read().await;
|
||||
let state_vec = state.to_vector();
|
||||
let state_tensor = Tensor::new(&*state_vec, &self.device)?.unsqueeze(0)?; // Add batch dimension
|
||||
let raw_dim = state_vec.len();
|
||||
let aligned = crate::dqn::mixed_precision::align_dim_for_tensor_cores(raw_dim, &self.device);
|
||||
let padded: Vec<f32> = if aligned > raw_dim {
|
||||
let mut v = state_vec.to_vec();
|
||||
v.resize(aligned, 0.0);
|
||||
v
|
||||
} else {
|
||||
state_vec.to_vec()
|
||||
};
|
||||
let state_tensor = Tensor::new(&*padded, &self.device)?.unsqueeze(0)?; // Add batch dimension
|
||||
|
||||
let q_values_tensor = agent.forward(&state_tensor)?;
|
||||
let q_values_vec = q_values_tensor.squeeze(0)?.to_vec1::<f32>()?;
|
||||
@@ -4221,11 +4230,20 @@ impl DQNTrainer {
|
||||
// Use internal conversion method (returns TradingState)
|
||||
let trading_state = self.feature_vector_to_state(feature_vec, Some(close))?;
|
||||
|
||||
// Convert TradingState to flat vector
|
||||
// Convert TradingState to flat vector, pad for tensor core alignment
|
||||
let state_vec = trading_state.to_vector();
|
||||
let raw_dim = state_vec.len();
|
||||
let aligned = crate::dqn::mixed_precision::align_dim_for_tensor_cores(raw_dim, &self.device);
|
||||
let padded: Vec<f32> = if aligned > raw_dim {
|
||||
let mut v = state_vec.to_vec();
|
||||
v.resize(aligned, 0.0);
|
||||
v
|
||||
} else {
|
||||
state_vec.to_vec()
|
||||
};
|
||||
|
||||
// Convert to Tensor using trainer's device (GPU or CPU)
|
||||
Tensor::new(state_vec.as_slice(), &self.device)
|
||||
Tensor::new(padded.as_slice(), &self.device)
|
||||
.context("Failed to create state tensor from TradingState")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user