-
Notifications
You must be signed in to change notification settings - Fork 23
Clean support for Non-Nvidia hardware vendors like Apple Silicon #63
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
Changes from all commits
f50471b
f7e9dac
d6051e0
35ac5d8
4779b9a
fb29400
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,11 +7,13 @@ | |
| import org.beehive.gpullama3.model.Configuration; | ||
| import org.beehive.gpullama3.tornadovm.kernels.TransformerComputeKernelsLayered; | ||
| import org.beehive.gpullama3.tornadovm.layerplanner.WorkerGridFactory; | ||
| import org.beehive.gpullama3.tornadovm.layerplanner.strategy.SchedulerType; | ||
| import org.beehive.gpullama3.tornadovm.layers.AbstractFFNLayers; | ||
| import uk.ac.manchester.tornado.api.GridScheduler; | ||
| import uk.ac.manchester.tornado.api.ImmutableTaskGraph; | ||
| import uk.ac.manchester.tornado.api.TaskGraph; | ||
| import uk.ac.manchester.tornado.api.WorkerGrid; | ||
| import uk.ac.manchester.tornado.api.common.TornadoFunctions; | ||
| import uk.ac.manchester.tornado.api.enums.DataTransferMode; | ||
|
|
||
| import java.util.List; | ||
|
|
@@ -21,9 +23,10 @@ public class LlamaFP16FFNLayers extends AbstractFFNLayers { | |
|
|
||
| TaskGraph ffnTaskGraphs; | ||
| GridScheduler scheduler; | ||
| List<ImmutableTaskGraph> ffnLayerTaskGraphs; | ||
| public LlamaFP16FFNLayers(String taskGraph, State state, Weights weights, Configuration config) { | ||
| super(taskGraph, state, weights, config); | ||
| List<ImmutableTaskGraph> ffnLayerTaskGraphs; | ||
|
|
||
| public LlamaFP16FFNLayers(String taskGraph, State state, Weights weights, Configuration config, org.beehive.gpullama3.tornadovm.layerplanner.strategy.SchedulerType schedulerType) { | ||
| super(taskGraph, state, weights, config, schedulerType); | ||
| this.ffnLayerTaskGraphs = setupFFNLayered(); | ||
| } | ||
|
|
||
|
|
@@ -111,9 +114,12 @@ TaskGraph setupSingleFFNLayer(FP16Weights weights, Configuration config, int lay | |
| weights.w2Layered[layerIndex], | ||
| weights.w3Layered[layerIndex]); | ||
| unifiedLayer = configureLayerDataTransfers(unifiedLayer, layerIndex); | ||
| unifiedLayer | ||
| .task("reductionsOneBlock", TransformerComputeKernelsLayered::reductionOneBlockWithLayer, context, state.temp, state.wrapX, config.dim(), config.rmsNormEps(), state.localSize) | ||
| .task("mapContext", TransformerComputeKernelsLayered::reductionOneBlock2WithLayer, context, state.wrapXb, state.wrapX, weights.rms_att_weightLayered[layerIndex], state.temp) | ||
| unifiedLayer.task("reductionsOneBlock", TransformerComputeKernelsLayered::reductionOneBlockWithLayer, context, state.temp, state.wrapX, config.dim(), config.rmsNormEps(), state.localSize); | ||
| if (shouldUseFinalNormalization()) { | ||
| unifiedLayer.task("reductionFinalNormalization", TransformerComputeKernelsLayered::reductionFinalNormalization, context, state.temp, | ||
| config.dim(), config.rmsNormEps()); | ||
| } | ||
| unifiedLayer.task("mapContext", TransformerComputeKernelsLayered::reductionOneBlock2WithLayer, context, state.wrapXb, state.wrapX, weights.rms_att_weightLayered[layerIndex], state.temp) | ||
| .task("qmatmul", TransformerComputeKernelsLayered::matrixVectorGeneric, context, state.wrapXb, state.wrapQ, weights.wqLayered[layerIndex], config.dim(), config.dim(), | ||
| LOCAL_WORK_GROUP_SIZE_ALLOC) | ||
| .task("kmatmul", TransformerComputeKernelsLayered::matrixVectorGeneric, context, state.wrapXb, state.wrapK, weights.wkLayered[layerIndex], config.dim(), config.kvDim(), | ||
|
|
@@ -122,14 +128,17 @@ TaskGraph setupSingleFFNLayer(FP16Weights weights, Configuration config, int lay | |
| LOCAL_WORK_GROUP_SIZE_ALLOC) | ||
| .task("rope", TransformerComputeKernelsLayered::ropeRotation, context, state.positionHolder, state.wrapQ, state.wrapK, config.kvDim(), config.headSize()) | ||
| .task("copyToCaches", TransformerComputeKernelsLayered::copyToCache, state.wrapKeyCache, state.wrapK, state.wrapValueCache, state.wrapV, state.positionHolder, config.kvDim(), | ||
| layerIndex, config.contextLength()) | ||
| .task("parallel-attention", TransformerComputeKernelsLayered::processHeadsFlashAttention, context, state.wrapQ, state.wrapKeyCache, state.wrapValueCache, state.wrapXb, | ||
| config.numberOfHeads(), config.headSize(), config.kvDim(), config.kvMul(), state.positionHolder, layerIndex, config.contextLength()) | ||
| .task("matmul1", TransformerComputeKernelsLayered::matrixVectorGenericWithResidual, context, state.wrapXb, state.wrapX, weights.woLayered[layerIndex], config.dim(), config.dim(), | ||
| layerIndex, config.contextLength()); | ||
| configureAttention(unifiedLayer, layerIndex); | ||
| unifiedLayer.task("matmul1", TransformerComputeKernelsLayered::matrixVectorGenericWithResidual, context, state.wrapXb, state.wrapX, weights.woLayered[layerIndex], config.dim(), config.dim(), | ||
| LOCAL_WORK_GROUP_SIZE_ALLOC) | ||
| .task("reductionsOneBlockFFN", TransformerComputeKernelsLayered::reductionOneBlockWithLayer, context, state.tempFFN, state.wrapX, config.dim(), config.rmsNormEps(), | ||
| state.localSize) | ||
| .task("mapContextFFN", TransformerComputeKernelsLayered::reductionOneBlock2WithLayer, context, state.wrapXb, state.wrapX, weights.rms_ffn_weightLayered[layerIndex], state.tempFFN) | ||
| state.localSize); | ||
| if (shouldUseFinalNormalization()) { | ||
| unifiedLayer.task("reductionFinalNormalizationFFN", TransformerComputeKernelsLayered::reductionFinalNormalization, context, state.tempFFN, | ||
| config.dim(), config.rmsNormEps()); | ||
| } | ||
| unifiedLayer.task("mapContextFFN", TransformerComputeKernelsLayered::reductionOneBlock2WithLayer, context, state.wrapXb, state.wrapX, weights.rms_ffn_weightLayered[layerIndex], state.tempFFN) | ||
| .task("fused_ffn_w1_w3", TransformerComputeKernelsLayered::fusedFeedForwardWithSiLUAndGLUActivation, context, state.wrapXb, state.wrapHb, weights.w1Layered[layerIndex], | ||
| weights.w3Layered[layerIndex], config.dim(), config.hiddenDim(), LOCAL_WORK_GROUP_SIZE_ALLOC) | ||
| .task("projectionTwo", TransformerComputeKernelsLayered::matrixVectorGenericWithResidual, context, state.wrapHb, state.wrapX, weights.w2Layered[layerIndex], config.hiddenDim(), | ||
|
|
@@ -159,4 +168,18 @@ protected TaskGraph configureLayerDataTransfers(TaskGraph unifiedLayer, int laye | |
| return unifiedLayer; | ||
| } | ||
|
|
||
| private TaskGraph configureAttention(TaskGraph unifiedLayer, int layerIndex) { | ||
| if (schedulerType == SchedulerType.NVIDIA) { | ||
| return unifiedLayer.task("parallel-attention", TransformerComputeKernelsLayered::processHeadsFlashAttention, | ||
| context, state.wrapQ, state.wrapKeyCache, state.wrapValueCache, state.wrapXb, | ||
| config.numberOfHeads(), config.headSize(), config.kvDim(), config.kvMul(), | ||
| state.positionHolder, layerIndex, config.contextLength()); | ||
| } else { | ||
| return unifiedLayer.task("parallel-attention", TransformerComputeKernelsLayered::processHeadsParallel, | ||
| state.wrapQ, state.wrapKeyCache, state.wrapValueCache, state.wrapXb, | ||
| config.numberOfHeads(), config.headSize(), config.kvDim(), config.kvMul(), config.contextLength(), | ||
| state.positionHolder, state.wrapAtt, layerIndex, config.contextLength()); | ||
|
||
| } | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.