-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76d456e
commit 5149f96
Showing
10 changed files
with
1,375 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use candle_core::{Module, Result, Tensor}; | ||
use candle_nn::VarBuilder; | ||
|
||
use super::paligemma; | ||
use candle_nn::{linear, Linear}; | ||
|
||
pub struct Model { | ||
pub model: paligemma::Model, | ||
pub custom_text_projection: Linear, | ||
} | ||
|
||
impl Model { | ||
pub fn new(config: &paligemma::Config, vb: VarBuilder) -> Result<Self> { | ||
let model = paligemma::Model::new(config, vb.pp("model"))?; | ||
let custom_text_projection = linear( | ||
config.text_config.hidden_size, | ||
128, | ||
vb.pp("custom_text_proj"), | ||
)?; | ||
|
||
Ok(Self { | ||
model, | ||
custom_text_projection, | ||
}) | ||
} | ||
|
||
pub fn forward_images(&mut self, pixel_values: &Tensor, input_ids: &Tensor) -> Result<Tensor> { | ||
let outputs = self | ||
.model | ||
.setup_without_projection(pixel_values, input_ids)?; | ||
let outputs = self.custom_text_projection.forward(&outputs)?; | ||
let outputs = outputs.broadcast_div(&outputs.sqr()?.sum_keepdim(2)?.sqrt()?)?; | ||
Ok(outputs) | ||
} | ||
|
||
pub fn forward_text(&mut self, input_ids: &Tensor) -> Result<Tensor> { | ||
let outputs = self.model.forward_without_projection(input_ids)?; | ||
let outputs = self.custom_text_projection.forward(&outputs)?; | ||
let outputs = outputs.broadcast_div(&outputs.sqr()?.sum_keepdim(2)?.sqrt()?)?; | ||
Ok(outputs) | ||
} | ||
} |
Oops, something went wrong.