Skip to content

Commit 3fe2c13

Browse files
authored
[js] small fix to workaround formatter (#19400)
### Description Rename shader variable names to snake_case naming and also to avoid formatter behaving inconsistently in win/linux.
1 parent 97ff17c commit 3fe2c13

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

js/web/lib/wasm/jsep/webgpu/ops/layer-norm.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,28 @@ const createLayerNormProgramInfo =
8585
${shaderHelper.mainStart()}
8686
${shaderHelper.guardAgainstOutOfBoundsWorkgroupSizes('uniforms.norm_count')}
8787
let offset = global_idx * uniforms.norm_size_vectorized;
88-
var meanVector = ${fillVector('f32', components)};
89-
var meanSquareVector = ${fillVector('f32', components)};
88+
var mean_vector = ${fillVector('f32', components)};
89+
var mean_square_vector = ${fillVector('f32', components)};
9090
9191
for (var h: u32 = 0u; h < uniforms.norm_size_vectorized; h++) {
9292
let value = ${castToF32(dataType, components, 'x[h + offset]')};
93-
meanVector += value;
94-
meanSquareVector += value * value;
93+
mean_vector += value;
94+
mean_square_vector += value * value;
9595
}
96-
let mean = ${sumVector('meanVector', components)} / uniforms.norm_size;
97-
let invStdDev =
98-
inverseSqrt(${sumVector('meanSquareVector', components)} / uniforms.norm_size - mean * mean + uniforms.epsilon);
96+
let mean = ${sumVector('mean_vector', components)} / uniforms.norm_size;
97+
let inv_std_dev = inverseSqrt(${
98+
sumVector('mean_square_vector', components)} / uniforms.norm_size - mean * mean + uniforms.epsilon);
9999
100100
for (var j: u32 = 0; j < uniforms.norm_size_vectorized; j++) {
101101
let f32input = ${castToF32(dataType, components, 'x[j + offset]')};
102102
let f32scale = ${castToF32(dataType, components, 'scale[j]')};
103-
output[j + offset] = ${variables[0].type.value}((f32input - mean) * invStdDev * f32scale
103+
output[j + offset] = ${variables[0].type.value}((f32input - mean) * inv_std_dev * f32scale
104104
${bias ? `+ ${castToF32(dataType, components, 'bias[j]')}` : ''}
105105
);
106106
}
107107
108108
${hasMeanDataOutput ? 'mean_data_output[global_idx] = mean' : ''};
109-
${hasInvStdOutput ? 'inv_std_output[global_idx] = invStdDev' : ''};
109+
${hasInvStdOutput ? 'inv_std_output[global_idx] = inv_std_dev' : ''};
110110
}`;
111111
};
112112
const outputs = [{dims: outputShape, dataType: inputs[0].dataType}];

0 commit comments

Comments
 (0)