Skip to content

revert qkv. #36

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

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
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
24 changes: 6 additions & 18 deletions src/grok1-tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,9 @@ TransformerArch buildGrok1Arch(TransformerSpec* spec) {
a.I(llamaRmsAttNorm, TASK_TYPE_INFERENCE);
a.I(llamaQuantizeRmsAtt, TASK_TYPE_INFERENCE);
a.I(llamaSyncRmsAtt, TASK_TYPE_TRANSFER);
a.I(llamaAttQ, TASK_TYPE_INFERENCE);
a.I(llamaQuantizeAttQ, TASK_TYPE_INFERENCE);
a.I(llamaSyncAttQ, TASK_TYPE_TRANSFER);
a.I(llamaAttK, TASK_TYPE_INFERENCE);
a.I(llamaQuantizeAttK, TASK_TYPE_INFERENCE);
a.I(llamaSyncAttK, TASK_TYPE_TRANSFER);
a.I(llamaAttV, TASK_TYPE_INFERENCE);
a.I(llamaQuantizeAttV, TASK_TYPE_INFERENCE);
a.I(llamaSyncAttV, TASK_TYPE_TRANSFER);
a.I(llamaQkv, TASK_TYPE_INFERENCE);
a.I(llamaQuantizeQkv, TASK_TYPE_INFERENCE);
a.I(llamaSyncQkv, TASK_TYPE_TRANSFER);
a.I(llamaDequantizeQkv, TASK_TYPE_INFERENCE);
a.I(llamaMultiheadAtt, TASK_TYPE_INFERENCE);
a.I(grokMultiheadAttRope, TASK_TYPE_INFERENCE);
Expand Down Expand Up @@ -364,15 +358,9 @@ TransformerArch buildGrok1Arch(TransformerSpec* spec) {

for (int i = 0; i < spec->nLayers; i++) {
a.W(llamaSyncRmsAtt, TASK_TYPE_TRANSFER);
a.W(llamaAttQ, TASK_TYPE_INFERENCE);
a.W(llamaQuantizeAttQ, TASK_TYPE_INFERENCE);
a.W(llamaSyncAttQ, TASK_TYPE_INFERENCE);
a.W(llamaAttK, TASK_TYPE_INFERENCE);
a.W(llamaQuantizeAttK, TASK_TYPE_INFERENCE);
a.W(llamaSyncAttK, TASK_TYPE_INFERENCE);
a.W(llamaAttV, TASK_TYPE_INFERENCE);
a.W(llamaQuantizeAttV, TASK_TYPE_INFERENCE);
a.W(llamaSyncAttV, TASK_TYPE_INFERENCE);
a.W(llamaQkv, TASK_TYPE_INFERENCE);
a.W(llamaQuantizeQkv, TASK_TYPE_INFERENCE);
a.W(llamaSyncQkv, TASK_TYPE_TRANSFER);
a.W(llamaSyncMultiheadAtt, TASK_TYPE_TRANSFER);
a.W(llamaAtt, TASK_TYPE_INFERENCE);
a.W(llamaQuantizeAtt, TASK_TYPE_INFERENCE);
Expand Down
72 changes: 18 additions & 54 deletions src/llama2-tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,56 +30,32 @@ void llamaSyncRmsAtt(TASK_ARGS) {
syncUnitBuffer(nThreads, threadIndex, ctx, TB_UNIT_XB_QUANTIZED);
}

void llamaAttQ(TASK_ARGS) {
void llamaQkv(TASK_ARGS) {
TASK_VARIABLES;
float *xbq = (float*)transformer->buffer->getUnit(TB_UNIT_XB_QUANTIZED);
float *q0 = (float*)transformer->buffer->getSliced(TB_SLICED_Q, transformer->sliceIndex);
matmul(spec->weightsFloatType, spec->bufferFloatType, q0, xbq, block->q0, block->q0Slice->n, block->q0Slice->d0, nThreads, threadIndex);
}

void llamaQuantizeAttQ(TASK_ARGS) {
TASK_VARIABLES;
quantizeSlicedBuffer(nThreads, threadIndex, ctx, false, TB_SLICED_Q, TB_SLICED_Q_QUANTIZED);
}

void llamaSyncAttQ(TASK_ARGS) {
TASK_VARIABLES;
syncSliceOfSlicedBuffer(nThreads, threadIndex, ctx, TB_SLICED_Q_QUANTIZED);
}

void llamaAttK(TASK_ARGS) {
TASK_VARIABLES;
float *xbq = (float*)transformer->buffer->getUnit(TB_UNIT_XB_QUANTIZED);
float *q0 = (float*)transformer->buffer->getSliced(TB_SLICED_Q, transformer->sliceIndex);
float *k0 = (float*)transformer->buffer->getSliced(TB_SLICED_K, transformer->sliceIndex);
matmul(spec->weightsFloatType, spec->bufferFloatType, k0, xbq, block->k0, block->k0Slice->n, block->k0Slice->d0, nThreads, threadIndex);
}

void llamaQuantizeAttK(TASK_ARGS) {
TASK_VARIABLES;
quantizeSlicedBuffer(nThreads, threadIndex, ctx, false, TB_SLICED_K, TB_SLICED_K_QUANTIZED);
}

void llamaSyncAttK(TASK_ARGS) {
TASK_VARIABLES;
syncSliceOfSlicedBuffer(nThreads, threadIndex, ctx, TB_SLICED_K_QUANTIZED);
}

void llamaAttV(TASK_ARGS) {
TASK_VARIABLES;
float *xbq = (float*)transformer->buffer->getUnit(TB_UNIT_XB_QUANTIZED);
float *v0 = (float*)transformer->buffer->getSliced(TB_SLICED_V, transformer->sliceIndex);
matmul(spec->weightsFloatType, spec->bufferFloatType, v0, xbq, block->v0, block->v0Slice->n, block->v0Slice->d0, nThreads, threadIndex);

matmul(spec->weightsFloatType, spec->bufferFloatType, q0, xbq, block->q0, block->q0Slice->n, block->q0Slice->d0, nThreads, threadIndex);
matmul(spec->weightsFloatType, spec->bufferFloatType, k0, xbq, block->k0, block->k0Slice->n, block->k0Slice->d0, nThreads, threadIndex);
matmul(spec->weightsFloatType, spec->bufferFloatType, v0, xbq, block->v0, block->v0Slice->n, block->v0Slice->d0, nThreads, threadIndex);
}

void llamaQuantizeAttV(TASK_ARGS) {
void llamaQuantizeQkv(TASK_ARGS) {
TASK_VARIABLES;
quantizeSlicedBuffer(nThreads, threadIndex, ctx, false, TB_SLICED_Q, TB_SLICED_Q_QUANTIZED);
quantizeSlicedBuffer(nThreads, threadIndex, ctx, false, TB_SLICED_K, TB_SLICED_K_QUANTIZED);
quantizeSlicedBuffer(nThreads, threadIndex, ctx, false, TB_SLICED_V, TB_SLICED_V_QUANTIZED);
}

void llamaSyncAttV(TASK_ARGS) {
void llamaSyncQkv(TASK_ARGS) {
TASK_VARIABLES;
syncSliceOfSlicedBuffer(nThreads, threadIndex, ctx, TB_SLICED_Q_QUANTIZED);
syncSliceOfSlicedBuffer(nThreads, threadIndex, ctx, TB_SLICED_K_QUANTIZED);
syncSliceOfSlicedBuffer(nThreads, threadIndex, ctx, TB_SLICED_V_QUANTIZED);
// if (ctx->socketPool != NULL && threadIndex == 0) { float* v = (float*)block->q0; printf("q0 (%d): %f %f %f %f %f %f\n", ctx->currentBlockIndex, v[0], v[1], v[2], v[3], v[4], v[5]); }
}

void llamaDequantizeQkv(TASK_ARGS) {
Expand Down Expand Up @@ -316,15 +292,9 @@ TransformerArch buildLlama2Arch(TransformerSpec* spec) {
a.I(llamaRmsAttNorm, TASK_TYPE_INFERENCE);
a.I(llamaQuantizeRmsAtt, TASK_TYPE_INFERENCE);
a.I(llamaSyncRmsAtt, TASK_TYPE_TRANSFER);
a.I(llamaAttQ, TASK_TYPE_INFERENCE);
a.I(llamaQuantizeAttQ, TASK_TYPE_INFERENCE);
a.I(llamaSyncAttQ, TASK_TYPE_TRANSFER);
a.I(llamaAttK, TASK_TYPE_INFERENCE);
a.I(llamaQuantizeAttK, TASK_TYPE_INFERENCE);
a.I(llamaSyncAttK, TASK_TYPE_TRANSFER);
a.I(llamaAttV, TASK_TYPE_INFERENCE);
a.I(llamaQuantizeAttV, TASK_TYPE_INFERENCE);
a.I(llamaSyncAttV, TASK_TYPE_TRANSFER);
a.I(llamaQkv, TASK_TYPE_INFERENCE);
a.I(llamaQuantizeQkv, TASK_TYPE_INFERENCE);
a.I(llamaSyncQkv, TASK_TYPE_TRANSFER);
a.I(llamaDequantizeQkv, TASK_TYPE_INFERENCE);
a.I(llamaMultiheadAtt, TASK_TYPE_INFERENCE);
a.I(llamaMultiheadAttRope, TASK_TYPE_INFERENCE);
Expand Down Expand Up @@ -359,15 +329,9 @@ TransformerArch buildLlama2Arch(TransformerSpec* spec) {

for (int i = 0; i < spec->nLayers; i++) {
a.W(llamaSyncRmsAtt, TASK_TYPE_TRANSFER);
a.W(llamaAttQ, TASK_TYPE_INFERENCE);
a.W(llamaQuantizeAttQ, TASK_TYPE_INFERENCE);
a.W(llamaSyncAttQ, TASK_TYPE_INFERENCE);
a.W(llamaAttK, TASK_TYPE_INFERENCE);
a.W(llamaQuantizeAttK, TASK_TYPE_INFERENCE);
a.W(llamaSyncAttK, TASK_TYPE_INFERENCE);
a.W(llamaAttV, TASK_TYPE_INFERENCE);
a.W(llamaQuantizeAttV, TASK_TYPE_INFERENCE);
a.W(llamaSyncAttV, TASK_TYPE_INFERENCE);
a.W(llamaQkv, TASK_TYPE_INFERENCE);
a.W(llamaQuantizeQkv, TASK_TYPE_INFERENCE);
a.W(llamaSyncQkv, TASK_TYPE_TRANSFER);
a.W(llamaSyncMultiheadAtt, TASK_TYPE_TRANSFER);
a.W(llamaAtt, TASK_TYPE_INFERENCE);
a.W(llamaQuantizeAtt, TASK_TYPE_INFERENCE);
Expand Down
12 changes: 3 additions & 9 deletions src/llama2-tasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ void llamaRmsAtt(TASK_ARGS);
void llamaRmsAttNorm(TASK_ARGS);
void llamaQuantizeRmsAtt(TASK_ARGS);
void llamaSyncRmsAtt(TASK_ARGS);
void llamaAttQ(TASK_ARGS);
void llamaQuantizeAttQ(TASK_ARGS);
void llamaSyncAttQ(TASK_ARGS);
void llamaAttK(TASK_ARGS);
void llamaQuantizeAttK(TASK_ARGS);
void llamaSyncAttK(TASK_ARGS);
void llamaAttV(TASK_ARGS);
void llamaQuantizeAttV(TASK_ARGS);
void llamaSyncAttV(TASK_ARGS);
void llamaQkv(TASK_ARGS);
void llamaQuantizeQkv(TASK_ARGS);
void llamaSyncQkv(TASK_ARGS);
void llamaDequantizeQkv(TASK_ARGS);
void llamaMultiheadAtt(TASK_ARGS);
void llamaMultiheadAttRope(TASK_ARGS);
Expand Down
24 changes: 6 additions & 18 deletions src/mixtral-tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@ TransformerArch buildMixtralArch(TransformerSpec* spec) {
a.I(llamaRmsAttNorm, TASK_TYPE_INFERENCE);
a.I(llamaQuantizeRmsAtt, TASK_TYPE_INFERENCE);
a.I(llamaSyncRmsAtt, TASK_TYPE_TRANSFER);
a.I(llamaAttQ, TASK_TYPE_INFERENCE);
a.I(llamaQuantizeAttQ, TASK_TYPE_INFERENCE);
a.I(llamaSyncAttQ, TASK_TYPE_TRANSFER);
a.I(llamaAttK, TASK_TYPE_INFERENCE);
a.I(llamaQuantizeAttK, TASK_TYPE_INFERENCE);
a.I(llamaSyncAttK, TASK_TYPE_TRANSFER);
a.I(llamaAttV, TASK_TYPE_INFERENCE);
a.I(llamaQuantizeAttV, TASK_TYPE_INFERENCE);
a.I(llamaSyncAttV, TASK_TYPE_TRANSFER);
a.I(llamaQkv, TASK_TYPE_INFERENCE);
a.I(llamaQuantizeQkv, TASK_TYPE_INFERENCE);
a.I(llamaSyncQkv, TASK_TYPE_TRANSFER);
a.I(llamaDequantizeQkv, TASK_TYPE_INFERENCE);
a.I(llamaMultiheadAtt, TASK_TYPE_INFERENCE);
a.I(grokMultiheadAttRope, TASK_TYPE_INFERENCE);
Expand Down Expand Up @@ -64,15 +58,9 @@ TransformerArch buildMixtralArch(TransformerSpec* spec) {

for (int i = 0; i < spec->nLayers; i++) {
a.W(llamaSyncRmsAtt, TASK_TYPE_TRANSFER);
a.W(llamaAttQ, TASK_TYPE_INFERENCE);
a.W(llamaQuantizeAttQ, TASK_TYPE_INFERENCE);
a.W(llamaSyncAttQ, TASK_TYPE_INFERENCE);
a.W(llamaAttK, TASK_TYPE_INFERENCE);
a.W(llamaQuantizeAttK, TASK_TYPE_INFERENCE);
a.W(llamaSyncAttK, TASK_TYPE_INFERENCE);
a.W(llamaAttV, TASK_TYPE_INFERENCE);
a.W(llamaQuantizeAttV, TASK_TYPE_INFERENCE);
a.W(llamaSyncAttV, TASK_TYPE_INFERENCE);
a.W(llamaQkv, TASK_TYPE_INFERENCE);
a.W(llamaQuantizeQkv, TASK_TYPE_INFERENCE);
a.W(llamaSyncQkv, TASK_TYPE_TRANSFER);
a.W(llamaSyncMultiheadAtt, TASK_TYPE_TRANSFER);
a.W(llamaAtt, TASK_TYPE_INFERENCE);
a.W(llamaQuantizeAtt, TASK_TYPE_INFERENCE);
Expand Down
Loading