mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-29 20:14:01 +00:00
[js/webgpu] Fix attention shader recompilation issue (#21770)
### Description <!-- Describe your changes. --> This PR fixes the `AttentionProbsSoftmax` recompilation issue when executing the phi3 model. With this fix, it will further improve the phi3 performance. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. -->
This commit is contained in:
parent
49fc168eed
commit
c4ade796d6
1 changed files with 3 additions and 5 deletions
|
|
@ -262,9 +262,7 @@ const createInPlaceSoftmaxProgramInfo = (_context: ComputeContext, input: Tensor
|
|||
let WG = 64;
|
||||
const dComp = d / components;
|
||||
if (dComp < WG) {
|
||||
WG = 1;
|
||||
} else if (dComp / 8 < 64) {
|
||||
WG = Math.ceil(dComp / 8);
|
||||
WG = 32;
|
||||
}
|
||||
const elementsPerThread = Math.ceil(d / components / WG);
|
||||
const programUniforms: ProgramUniform[] = [
|
||||
|
|
@ -274,7 +272,7 @@ const createInPlaceSoftmaxProgramInfo = (_context: ComputeContext, input: Tensor
|
|||
];
|
||||
const dataType = tensorTypeToWsglStorageType(input.dataType, components);
|
||||
const f32Type = tensorTypeToWsglValueType(DataType.float, components);
|
||||
|
||||
const inputDependencies: ProgramInputTensorInfoDependency[] = ['type'];
|
||||
const getShaderSource = (shaderHelper: ShaderHelper) => {
|
||||
const inputHelper = outputVariable('x', input.dataType, input.dims, components);
|
||||
const elemValueType = tensorTypeToWsglValueType(input.dataType);
|
||||
|
|
@ -353,7 +351,7 @@ const createInPlaceSoftmaxProgramInfo = (_context: ComputeContext, input: Tensor
|
|||
|
||||
return {
|
||||
name: 'AttentionProbsSoftmax',
|
||||
shaderCache: { hint: `${WG};${dataType};${components}` },
|
||||
shaderCache: { hint: `${WG};${dataType};${components}`, inputDependencies },
|
||||
getShaderSource,
|
||||
getRunData: () => ({ outputs: [], dispatchGroup: { x: n }, programUniforms }),
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue