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

Fix handling of bias column vectors when K=0 #526

Merged
merged 1 commit into from
Jan 9, 2025
Merged
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
6 changes: 3 additions & 3 deletions src/gemm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ fn gemm_impl<LhsT: GemmInT, RhsT: GemmInT, OutT: GemmOutT>(
if let Some(bias) = bias {
let bias_mat = match bias {
BiasVector::Column(bias) => {
NdTensorView::from_data([a.rows()], bias).broadcast([a.rows(), b.cols()])
NdTensorView::from_data([a.rows(), 1], bias).broadcast([a.rows(), b.cols()])
}
BiasVector::Row(bias) => {
NdTensorView::from_data([1, b.cols()], bias).broadcast([a.rows(), b.cols()])
Expand Down Expand Up @@ -1640,7 +1640,7 @@ mod tests {
// Vector-matrix, where n > minimum block size
Case { m: 1, n: 129, k: 1 },
// Case where k == 0
Case { m: 5, n: 5, k: 0 },
Case { m: 5, n: 7, k: 0 },
];

for Case { m, n, k } in cases {
Expand Down Expand Up @@ -1669,6 +1669,7 @@ mod tests {
0.,
Some(BiasVector::Column(&bias)),
);
expect_equal(&result, &expected)?;

// Row vector bias
let bias: Vec<f32> = (0..b.cols()).map(|b| b as f32).collect();
Expand All @@ -1689,7 +1690,6 @@ mod tests {
0.,
Some(BiasVector::Row(&bias)),
);

expect_equal(&result, &expected)?;
}

Expand Down
Loading