repo_name stringlengths 1 62 | dataset stringclasses 1
value | lang stringclasses 11
values | pr_id int64 1 20.1k | owner stringlengths 2 34 | reviewer stringlengths 2 39 | diff_hunk stringlengths 15 262k | code_review_comment stringlengths 1 99.6k |
|---|---|---|---|---|---|---|---|
xFasterTransformer | github_2023 | cpp | 375 | intel | Duyi-Wang | @@ -0,0 +1,348 @@
+// Copyright (c) 2023 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless require... | I prefer to prepare KVCache at a high level api.
We can assume all seqs' KVCache is ready. |
xFasterTransformer | github_2023 | cpp | 348 | intel | abenmao | @@ -596,4 +648,135 @@ void crossAttnShardedHead(T1 *output, const T1 *query, const float *attnMask, in
} // end for b
}
+/**
+ * @brief Cross attention with head granularity (including copy key/value to KV Cache)
+ * @note if causal = True, attnMask is not used
+ * @tparam T Data type
+ * @tparam KVCacheT KV ca... | "const float *" is ok both for alibiSlopes and attnMask |
xFasterTransformer | github_2023 | cpp | 348 | intel | abenmao | @@ -596,4 +648,135 @@ void crossAttnShardedHead(T1 *output, const T1 *query, const float *attnMask, in
} // end for b
}
+/**
+ * @brief Cross attention with head granularity (including copy key/value to KV Cache)
+ * @note if causal = True, attnMask is not used
+ * @tparam T Data type
+ * @tparam KVCacheT KV ca... | During the decoding phase, the softmax computing is the same whether causal is False๏ผchatglm๏ผ or True, so โcausalโ can be omitted in the โif conditionโ |
xFasterTransformer | github_2023 | cpp | 348 | intel | abenmao | @@ -596,4 +648,135 @@ void crossAttnShardedHead(T1 *output, const T1 *query, const float *attnMask, in
} // end for b
}
+/**
+ * @brief Cross attention with head granularity (including copy key/value to KV Cache)
+ * @note if causal = True, attnMask is not used
+ * @tparam T Data type
+ * @tparam KVCacheT KV ca... | For the Baichuan model, alibiSlopes[i] need to be used in the softmax calculation; I will add a calculation function later. |
xFasterTransformer | github_2023 | cpp | 371 | intel | Duyi-Wang | @@ -0,0 +1,216 @@
+// Copyright (c) 2024 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless require... | default value for prefixID is better to be -1? since the ID starts from 0. |
xFasterTransformer | github_2023 | cpp | 371 | intel | Duyi-Wang | @@ -0,0 +1,216 @@
+// Copyright (c) 2024 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless require... | =๏ผ |
xFasterTransformer | github_2023 | cpp | 369 | intel | Duyi-Wang | @@ -530,13 +530,67 @@ class CommonDecoder : public AbstractDecoder {
TimeLine t("Decoder.forward");
TimeLine t1("Decoder.embedding");
+ // Prepare input
+ int totInputSeqLen = 0;
+ std::vector<int> allInputIds;
+ for (auto seq : seqs) {
+ // TODO: maybe not cor... | Assume input is prompt+past_generated_tokens.
getInputSeqLen() gets the size of prompt, getLatestToken() return the past_generated_tokens. |
xFasterTransformer | github_2023 | cpp | 369 | intel | changqi1 | @@ -67,63 +67,71 @@ class SequenceIDManager {
// The SequenceMeta is one sequence of batch inputs and includes the generated tokens.
class SequenceMeta {
public:
- SequenceMeta(std::vector<int32_t> &_inputTokens)
+ SequenceMeta(std::vector<int32_t> &_promptTokens)
: sequenceID(SequenceIDManager::getIn... | ไผๅ่ฟๅๅผไผ่ฟ่กcopy๏ผๅฝฑๅๆง่ฝ |
xFasterTransformer | github_2023 | cpp | 369 | intel | changqi1 | @@ -67,63 +67,71 @@ class SequenceIDManager {
// The SequenceMeta is one sequence of batch inputs and includes the generated tokens.
class SequenceMeta {
public:
- SequenceMeta(std::vector<int32_t> &_inputTokens)
+ SequenceMeta(std::vector<int32_t> &_promptTokens)
: sequenceID(SequenceIDManager::getIn... | ไผๅ่ฟๅๅผไผ่ฟ่กcopy๏ผๅฝฑๅๆง่ฝ |
xFasterTransformer | github_2023 | cpp | 370 | intel | Duyi-Wang | @@ -47,4 +47,4 @@ class OptDecoder : public CommonDecoder<Attention<WeiT, QKPO_Dummy, LayerNorm>,
LayerNorm finalLN;
};
-REGISTER_MODEL(OptDecoder, gpt)
+REGISTER_MODEL(OptDecoder, opt) | It should be 'gpt' since the model type in the converted config.ini is gpt. |
xFasterTransformer | github_2023 | cpp | 370 | intel | Duyi-Wang | @@ -122,3 +122,5 @@ template <typename WeiT, typename KVCacheT>
void OptDecoder<WeiT, KVCacheT>::lastLayerNormForward(float *input, float *output, int rows) {
finalLN.forward(input, output, rows);
}
+
+IMPLEMENT_MODEL(OptDecoder, opt) | Should be gpt. |
xFasterTransformer | github_2023 | cpp | 366 | intel | abenmao | @@ -36,9 +36,17 @@ class Model {
void config(SearcherConfig &config_, const std::vector<std::vector<int>> &stopWordsList_ = {});
+ void set_input(std::vector<int32_t> &inputIds_, int batchSize_, int maxLen_ = -1, int numBeams_ = 1,
+ int numBeamHypsToKeep_ = 1, float lenPenalty_ = 1.0, bool doEar... | default to false |
xFasterTransformer | github_2023 | cpp | 332 | intel | Duyi-Wang | @@ -0,0 +1,210 @@
+// Copyright (c) 2024 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless require... | ้ๅผ`4`ไป็ฏๅขไธญpiplineๆฐ้ๆ่
่ชๅฎไน่ฎพ็ฝฎ๏ผ |
xFasterTransformer | github_2023 | cpp | 332 | intel | Duyi-Wang | @@ -0,0 +1,210 @@
+// Copyright (c) 2024 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless require... | set()? return bool. If not find return false else true. |
xFasterTransformer | github_2023 | cpp | 332 | intel | Duyi-Wang | @@ -0,0 +1,210 @@
+// Copyright (c) 2024 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless require... | bool? if key is existed, return false? |
xFasterTransformer | github_2023 | cpp | 332 | intel | Duyi-Wang | @@ -0,0 +1,210 @@
+// Copyright (c) 2024 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless require... | beamsearch้่ฆๅๅ
ไธๅฑ๏ผๆฏๅฆ็จSampleGroupMetaใ
https://github.com/vllm-project/vllm/blob/main/vllm/sequence.py#L547 |
xFasterTransformer | github_2023 | cpp | 332 | intel | Duyi-Wang | @@ -0,0 +1,210 @@
+// Copyright (c) 2024 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless require... | Not used. |
xFasterTransformer | github_2023 | cpp | 332 | intel | pujiang2018 | @@ -0,0 +1,275 @@
+// Copyright (c) 2024 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless require... | Is it better to design function like below to merge addNextToken and setStep:
void stepForward(int id)
(and in future, the id could be a vector)
inside that function, we can manage step and other changed members. |
xFasterTransformer | github_2023 | cpp | 332 | intel | pujiang2018 | @@ -64,6 +64,7 @@ struct DecoderContext {
int inputSeqLen;
// For custom usage
int reserved1;
+ int sequenceID; | why do we need it here? |
xFasterTransformer | github_2023 | cpp | 332 | intel | Duyi-Wang | @@ -0,0 +1,286 @@
+// Copyright (c) 2024 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless require... | Make SequenceGroup as the base unit of Sequencepool. |
xFasterTransformer | github_2023 | cpp | 321 | intel | pujiang2018 | @@ -621,3 +626,43 @@ class DecoderUtil {
return false;
}
};
+
+class DecoderFactory {
+public:
+ using CreateFunc = std::function<AbstractDecoder *(const std::string &)>;
+
+ static void Register(const std::string &key, CreateFunc createFunc) { GetRegistry()[key] = createFunc; }
+
+ static A... | it's better to move REGISTER_DECODER and related code to CommonDecoder or a separate place. for util folder, it should be completely decoupled from the structure related to xFT. In future, we need to make 'util' a real utility folder. |
xFasterTransformer | github_2023 | cpp | 321 | intel | pujiang2018 | @@ -40,3 +40,19 @@ class Baichuan : public CommonDecoder<BaichuanAttention<WeiT, LlamaRotaryEmbeddi
TokenEmbedding<float16_t> *embedding;
RmsNorm finalLN;
};
+
+REGISTER_DECODER(Baichuan, baichuan, float) | Move to cpp file is better, suppose 2 cpp files include baichuan.h, then the model will be registered twice. |
xFasterTransformer | github_2023 | others | 337 | intel | marvin-Yu | @@ -105,169 +118,183 @@ rls_test_case=$(
# | qwen-14b | โ | โ | โ | โ | โ | โ | 32 | 32 |
# llama-2-7b with short prompt & full data type:
-bash run_benchmark.sh -m llama-2-7b -d fp16 -i 1 -w 0 -in 32 -out 32 -s 1
-bash run_benchmark.sh -m llama-2-7b -d bf16 -i 1 -w 0 -in 32 -out 32 -s 1
-... | typing error |
xFasterTransformer | github_2023 | others | 337 | intel | marvin-Yu | @@ -41,48 +41,61 @@ _test_case=$(
# | gemma-7b | โ | โ | ร | ร | ร | ร | 32 | 32 | | Should we add the "-kvd" parameter to this table for better understanding of our test case coverage? |
xFasterTransformer | github_2023 | cpp | 334 | intel | marvin-Yu | @@ -0,0 +1,163 @@
+#include "attention_kernels.h"
+#include "gemm_kernel_ext.h"
+#include "gtest/gtest.h"
+
+#include <cstdlib>
+
+// Define a fixture for the unit tests
+class AttentionKernelsTest : public ::testing::Test {
+protected:
+ void SetUp() override {
+ // Set up any necessary data or resources for... | didn't see what the specific differences are between these two sets of test cases. Can we use a more specific naming convention for the test cases? Also, since we already support the int8 kvcache format, should it be reflected in this unit test? |
xFasterTransformer | github_2023 | cpp | 259 | intel | pujiang2018 | @@ -218,6 +218,7 @@ class Attention {
bool useSelfAttn, bool doLnBefore, int *positionIds = nullptr) {
auto hiddenSize = ctx->hiddenSize;
+ auto attSize = ctx->attHeadNum * ctx->attHeadSize; | if 'attSize' not used, let's remove it. |
xFasterTransformer | github_2023 | cpp | 259 | intel | pujiang2018 | @@ -199,7 +211,16 @@ class LlamaMLP : public SingletonBase<LlamaMLP<WeiT>> {
const float *sumB = gateWeightSum.Data();
ImT *C = output.Data();
- ctx->mmHelper->compute_silu(false, M, N, K, 1.0f, A, lda, B, scaleB, zeroB, sumB, 0.0f, C, ldc);
+ if (ctx->actType == DecoderContext::SILU) ... | let's use the original path. |
xFasterTransformer | github_2023 | cpp | 259 | intel | changqi1 | @@ -453,6 +453,36 @@ class DecoderUtil {
}
}
+ // compute gelu on the left half and then add it with the right half
+ template <typename T1, typename T2>
+ static void geluSum(hpj::Matrix<T1> &src, hpj::Matrix<T2> &dst) {
+ __m512 c1 = _mm512_set1_ps(0.044715f); | const |
xFasterTransformer | github_2023 | cpp | 330 | intel | pujiang2018 | @@ -0,0 +1,66 @@
+// Copyright (c) 2023-2024 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless req... | What's the error when put such macro to cpp file? |
xFasterTransformer | github_2023 | others | 330 | intel | Duyi-Wang | @@ -1,5 +1,5 @@
#!/bin/bash
-# set -x | unset |
xFasterTransformer | github_2023 | others | 330 | intel | changqi1 | @@ -0,0 +1,27 @@
+{
+ "architectures": [
+ "Qwen2ForCausalLM"
+ ],
+ "attention_dropout": 0.0,
+ "bos_token_id": 151643,
+ "eos_token_id": 151645,
+ "hidden_act": "silu",
+ "hidden_size": 1024,
+ "initializer_range": 0.02,
+ "intermediate_size": 2816,
+ "max_position_embeddings": 32768,
+ "max_window_laye... | what is the meaning for max_window_layers? |
xFasterTransformer | github_2023 | cpp | 320 | intel | abenmao | @@ -463,8 +463,9 @@ class Attention {
auto srcV = value.Row(b * ctx->inputSeqLen + seq) + h * headSize;
auto dstV = presentValue.getSequence(pastSeqLen + seq, b, h);
- xft::copy(dstK, srcK, headSize);
- xft::copy(dstV, srcV, headSize);
+ ... | Since there are type conversions in storeKVCache. The old comments can be removed. |
xFasterTransformer | github_2023 | cpp | 320 | intel | changqi1 | @@ -478,19 +478,26 @@ class Attention {
for (int seq = 0; seq < ctx->inputSeqLen; ++seq) {
auto src = kv.Row(bdx * ctx->inputSeqLen + seq) + hdx * ctx->attHeadSize;
auto dst = presentKV.getSequence(pastSeqLen + seq, bdx, hdx);
- xft::copy(dst, src, ctx->attHeadSize);
+ ... | gemm1 -> gemm_query? |
xFasterTransformer | github_2023 | cpp | 320 | intel | changqi1 | @@ -504,12 +511,18 @@ class Attention {
// score: M * K(keyLen), value: K * headSize, output: M * headSize
template <typename T1, typename T2, typename T3>
- void gemm2(T1 *score, T2 *value, T3 *output, int M, int headSize, int K, int lds, int ldv, int ldo) {
+ void gemm2(T1 *score, const std::tuple<T... | gemm2 -> gemm_score? |
xFasterTransformer | github_2023 | others | 323 | intel | pujiang2018 | @@ -183,6 +183,9 @@ add_definitions(-DAVX512_FP32_WEIGHT_ONLY_NF4=true)
# add_definitions(-DSTEP_BY_STEP_ATTN=true)
add_definitions(-DUSE_SHM=true)
option(XFT_BUILD_TESTS "Build xfastertransformer unit tests" OFF)
+if(XFT_BUILD_TESTS)
+add_definitions(-DUNDEBUG=true) | why do we need UNDEBUG? |
xFasterTransformer | github_2023 | cpp | 319 | intel | pujiang2018 | @@ -70,6 +76,7 @@ class Model {
std::vector<int32_t> inputIds;
int batchSize;
int seqLen;
+ int vocabSize_; | Why do we need vocabSize in Model class?
if needed, could you pls make it in same naming style? |
xFasterTransformer | github_2023 | cpp | 319 | intel | pujiang2018 | @@ -129,6 +129,25 @@ struct TorchAutoModel : torch::CustomClassHolder {
doSample, temperature, topK, topP, repetitionPenalty, stopWordsList_int32);
}
+ torch::Tensor forward(torch::Tensor &inputIds) {
+ int batchSize = inputIds.size(0);
+ int seqLen = inputIds.size(1);
+ ... | For the original code, why 'input' method is not called 'setInput', input is more like a keyword, :( |
xFasterTransformer | github_2023 | cpp | 319 | intel | Duyi-Wang | @@ -129,6 +129,25 @@ struct TorchAutoModel : torch::CustomClassHolder {
doSample, temperature, topK, topP, repetitionPenalty, stopWordsList_int32);
}
+ torch::Tensor forward(torch::Tensor &inputIds) {
+ int batchSize = inputIds.size(0);
+ int seqLen = inputIds.size(1);
+ ... | Shape is correct? The decoder just returns the last token's logits. |
xFasterTransformer | github_2023 | cpp | 319 | intel | Duyi-Wang | @@ -129,6 +129,25 @@ struct TorchAutoModel : torch::CustomClassHolder {
doSample, temperature, topK, topP, repetitionPenalty, stopWordsList_int32);
}
+ torch::Tensor forward(torch::Tensor &inputIds) {
+ int batchSize = inputIds.size(0);
+ int seqLen = inputIds.size(1);
+ ... | Sync in multi-ranks? |
xFasterTransformer | github_2023 | cpp | 301 | intel | changqi1 | @@ -87,65 +87,112 @@ void ChatGLM2RotaryEmbedding::glm2CalEmb() {
// x_out2 = x_out2.flatten(3)
// return torch.cat((x_out2, x_pass), dim=-1)
-void ChatGLM2RotaryEmbedding::forward(float *buf, int bufStride, int batch_size, int seq_len, int qk_size,
- int hidden_size_per_attention_head, const int *po... | ```c++
#include <immintrin.h>
#include <stdio.h>
void interleave_merge(__m512 a, __m512 b, __m512 *result) {
// ็ๆๆฉ็
//__m512i mask = _mm512_set_epi32(0x17, 0x07, 0x16, 0x06, 0x15, 0x05, 0x14, 0x04, 0x13, 0x03, 0x12, 0x02, 0x11, 0x01, 0x10, 0x00);
__m512i mask = _mm512_set_epi32(0x1f, 0x0f, 0x1e, 0x... |
xFasterTransformer | github_2023 | cpp | 301 | intel | changqi1 | @@ -87,65 +87,112 @@ void ChatGLM2RotaryEmbedding::glm2CalEmb() {
// x_out2 = x_out2.flatten(3)
// return torch.cat((x_out2, x_pass), dim=-1)
-void ChatGLM2RotaryEmbedding::forward(float *buf, int bufStride, int batch_size, int seq_len, int qk_size,
- int hidden_size_per_attention_head, const int *po... | Delete those |
xFasterTransformer | github_2023 | cpp | 301 | intel | changqi1 | @@ -35,10 +36,12 @@ class ChatGLM2RotaryEmbedding {
~ChatGLM2RotaryEmbedding() {}
- void forward(float *buf, int bufStride, int batch_size, int seq_len, int qk_size,
- int hidden_size_per_attention_head, const int *position_ids);
+ // void forward(float *buf, int bufStride, int batch_size, int... | delete those. |
xFasterTransformer | github_2023 | cpp | 301 | intel | changqi1 | @@ -21,8 +21,13 @@
template <typename WeiT>
ChatGLM2<WeiT>::ChatGLM2(const std::string &modelPath, const std::string &modelType)
- : CommonDecoder<Attention<WeiT, ChatGLM2RotaryEmbedding, RmsNorm, float, float, float, true>,
- ChatGLM2MLP<WeiT, float, float, float, RmsNorm, true>>(modelPath, modelType... | delete those. |
xFasterTransformer | github_2023 | cpp | 301 | intel | changqi1 | @@ -23,15 +23,23 @@
#include "token_embedding.h"
template <typename WeiT>
-class ChatGLM2 : public CommonDecoder<Attention<WeiT, ChatGLM2RotaryEmbedding, RmsNorm, float, float, float, true>,
- ChatGLM2MLP<WeiT, float, float, float, RmsNorm, true>> {
+class ChatGLM2
+ : public CommonDecode... | delete those. |
xFasterTransformer | github_2023 | cpp | 301 | intel | changqi1 | @@ -138,17 +108,52 @@ void ChatGLM2RotaryEmbedding::forward(
float *psin = emb_sin + pos * dim;
#pragma omp simd
- for (int i = 0; i < dim; i += 2) {
+ for (int i = 0; i < half; i += 2) {
auto t1 = p1[i];
- p1[i] = p1[i] * pcos[i ... | const __m512i |
xFasterTransformer | github_2023 | cpp | 301 | intel | changqi1 | @@ -138,17 +108,52 @@ void ChatGLM2RotaryEmbedding::forward(
float *psin = emb_sin + pos * dim;
#pragma omp simd
- for (int i = 0; i < dim; i += 2) {
+ for (int i = 0; i < half; i += 2) {
auto t1 = p1[i];
- p1[i] = p1[i] * pcos[i ... | const __m512i |
xFasterTransformer | github_2023 | cpp | 301 | intel | changqi1 | @@ -138,17 +108,52 @@ void ChatGLM2RotaryEmbedding::forward(
float *psin = emb_sin + pos * dim;
#pragma omp simd
- for (int i = 0; i < dim; i += 2) {
+ for (int i = 0; i < half; i += 2) {
auto t1 = p1[i];
- p1[i] = p1[i] * pcos[i ... | const __m512i |
xFasterTransformer | github_2023 | cpp | 301 | intel | changqi1 | @@ -138,17 +108,52 @@ void ChatGLM2RotaryEmbedding::forward(
float *psin = emb_sin + pos * dim;
#pragma omp simd
- for (int i = 0; i < dim; i += 2) {
+ for (int i = 0; i < half; i += 2) {
auto t1 = p1[i];
- p1[i] = p1[i] * pcos[i ... | const __m512i |
xFasterTransformer | github_2023 | cpp | 301 | intel | changqi1 | @@ -138,17 +108,52 @@ void ChatGLM2RotaryEmbedding::forward(
float *psin = emb_sin + pos * dim;
#pragma omp simd
- for (int i = 0; i < dim; i += 2) {
+ for (int i = 0; i < half; i += 2) {
auto t1 = p1[i];
- p1[i] = p1[i] * pcos[i ... | *result0 = _mm512_permutex2var_ps(a, mask0, b); Why not? |
xFasterTransformer | github_2023 | cpp | 301 | intel | changqi1 | @@ -138,17 +108,52 @@ void ChatGLM2RotaryEmbedding::forward(
float *psin = emb_sin + pos * dim;
#pragma omp simd
- for (int i = 0; i < dim; i += 2) {
+ for (int i = 0; i < half; i += 2) {
auto t1 = p1[i];
- p1[i] = p1[i] * pcos[i ... | const __m512i |
xFasterTransformer | github_2023 | cpp | 301 | intel | changqi1 | @@ -111,41 +113,87 @@ void ChatGLM2RotaryEmbedding::forward(float *buf, int bufStride, int batch_size,
p1[i] = p1[i] * pcos[i] - p1[i + 1] * psin[i];
p1[i + 1] = p1[i + 1] * pcos[i] + t1 * psin[i];
}
- off += bufStride;
+ off += qS... | Why not to use it to parallel for? |
xFasterTransformer | github_2023 | cpp | 302 | intel | abenmao | @@ -54,6 +54,38 @@ void invokeMLPLLaMA(DataType dt, int numTokens, int hiddenSize, int intermediate
llama_mlp = it_created->second;
}
+ ctx->resize(1, numTokens, 0);
+ llama_mlp->forward(ctx, (float *)const_cast<void *>(input), (float *)output, inputStride, outputStride, false);
+ ... | Can these duplicated or similar code lines for fp16 be reused for the bf16 section? |
xFasterTransformer | github_2023 | cpp | 294 | intel | changqi1 | @@ -0,0 +1,231 @@
+#include <algorithm>
+#include "attention_kernels.h"
+#include "matmul_helper.h"
+#include "gtest/gtest.h"
+
+// Reference implementation of matrix multiplication
+static void mmRef(
+ bfloat16_t *A, bfloat16_t *B, bfloat16_t *C, int M, int N, int K, int lda, int ldb, int ldc, bool transB) {
+... | #pragma omp parallel for |
xFasterTransformer | github_2023 | cpp | 272 | intel | Duyi-Wang | @@ -0,0 +1,54 @@
+// Copyright (c) 2024 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required... | Add this ENV in environment.h? |
xFasterTransformer | github_2023 | python | 276 | intel | changqi1 | @@ -210,3 +210,189 @@ def split_and_convert(self, input_dir, output_dir, dtype, processes):
pool.starmap_async(self.split_and_convert_process, starmap_args)
pool.close()
pool.join()
+
+ def split_and_convert_quantized_model(self, input_dir, output_dir, dtype, processes, quantizatio... | uint4x2 |
xFasterTransformer | github_2023 | python | 276 | intel | changqi1 | @@ -210,3 +210,189 @@ def split_and_convert(self, input_dir, output_dir, dtype, processes):
pool.starmap_async(self.split_and_convert_process, starmap_args)
pool.close()
pool.join()
+
+ def split_and_convert_quantized_model(self, input_dir, output_dir, dtype, processes, quantizatio... | quant_decoder_weights -> quant_weight_data_type
int8,uint8,int4,uint4,fp8,fp4 |
xFasterTransformer | github_2023 | python | 276 | intel | changqi1 | @@ -53,16 +53,22 @@ def get_weight_data_type(self, dtype: str):
else:
raise Exception(f"{self.__class__.__name__} don't support convert weight to {dtype}.")
- def convert(self, input_dir, output_dir=None, dtype: str = "fp16", processes=8):
+ def convert(self, input_dir, output_dir=None, dt... | \# from_quantized_model is from HF int8 model to xFT int8 model.
def convert(self, input_dir, output_dir=None, dtype: str = "fp16", processes=8, from_quantized_model=None): |
xFasterTransformer | github_2023 | python | 276 | intel | changqi1 | @@ -210,3 +210,189 @@ def split_and_convert(self, input_dir, output_dir, dtype, processes):
pool.starmap_async(self.split_and_convert_process, starmap_args)
pool.close()
pool.join()
+
+ def split_and_convert_quantized_model(self, input_dir, output_dir, dtype, processes, quantizatio... | [ERROR] Please input model must be {quantization} quantized model. |
xFasterTransformer | github_2023 | python | 276 | intel | changqi1 | @@ -210,3 +210,189 @@ def split_and_convert(self, input_dir, output_dir, dtype, processes):
pool.starmap_async(self.split_and_convert_process, starmap_args)
pool.close()
pool.join()
+
+ def split_and_convert_quantized_model(self, input_dir, output_dir, dtype, processes, quantizatio... | \# load the quantized model, do not do GPTQ quantization. |
xFasterTransformer | github_2023 | python | 276 | intel | changqi1 | @@ -210,3 +210,189 @@ def split_and_convert(self, input_dir, output_dir, dtype, processes):
pool.starmap_async(self.split_and_convert_process, starmap_args)
pool.close()
pool.join()
+
+ def split_and_convert_quantized_model(self, input_dir, output_dir, dtype, processes, quantizatio... | zeros is uint8/uint4 from QPTQ quantization, and need to convert to fp32 for xFT. |
xFasterTransformer | github_2023 | python | 276 | intel | changqi1 | @@ -210,3 +210,189 @@ def split_and_convert(self, input_dir, output_dir, dtype, processes):
pool.starmap_async(self.split_and_convert_process, starmap_args)
pool.close()
pool.join()
+
+ def split_and_convert_quantized_model(self, input_dir, output_dir, dtype, processes, quantizatio... | scales is fp16/fp32/bf16 from QPTQ quantization, and need to convert to fp32 for xFT. |
xFasterTransformer | github_2023 | python | 276 | intel | changqi1 | @@ -210,3 +210,189 @@ def split_and_convert(self, input_dir, output_dir, dtype, processes):
pool.starmap_async(self.split_and_convert_process, starmap_args)
pool.close()
pool.join()
+
+ def split_and_convert_quantized_model(self, input_dir, output_dir, dtype, processes, quantizatio... | convert uint8 qweight from QPTQ quantization, and need to convert to int8 for xFT.
convert uint4 qweight from QPTQ quantization, and need to convert to uint4x2 for xFT. |
xFasterTransformer | github_2023 | cpp | 279 | intel | pujiang2018 | @@ -21,6 +21,8 @@
#include "allocator.h"
+extern bool kvTrans();
+
/**
* Tensor specially designed for KV Cache
* Naturaly, it could be represented in the shape of [seq_length][batch_size][head_num][head_size] | Please also modify the comments here? |
xFasterTransformer | github_2023 | cpp | 279 | intel | pujiang2018 | @@ -18,14 +18,41 @@
bool enableCATMLP() {
static int catMlp = -1;
- if (catMlp == -1)
- catMlp = (getenv("ENABLE_CAT_MLP") ? atoi(getenv("ENABLE_CAT_MLP")) : 1);
+ if (catMlp == -1) catMlp = (getenv("ENABLE_CAT_MLP") ? atoi(getenv("ENABLE_CAT_MLP")) : 1);
return catMlp == 1;
}
+bool tunedCo... | please remove it if not used. |
xFasterTransformer | github_2023 | cpp | 279 | intel | pujiang2018 | @@ -18,14 +18,41 @@
bool enableCATMLP() {
static int catMlp = -1;
- if (catMlp == -1)
- catMlp = (getenv("ENABLE_CAT_MLP") ? atoi(getenv("ENABLE_CAT_MLP")) : 1);
+ if (catMlp == -1) catMlp = (getenv("ENABLE_CAT_MLP") ? atoi(getenv("ENABLE_CAT_MLP")) : 1);
return catMlp == 1;
}
+bool tunedCo... | it is not so easy to understand "Tuned communication". add some comment? |
xFasterTransformer | github_2023 | python | 274 | intel | changqi1 | @@ -123,7 +123,14 @@ def split_and_convert(self, input_dir, output_dir, dtype, processes):
config["llama"]["num_layer"] = str(hf_config["num_hidden_layers"])
config["llama"]["layernorm_eps"] = str(hf_config.get("rms_norm_eps", 1e-6))
config["llama"]["layernorm_type"] = "pre_layern... | ๆLLaMaๅdeepseek็codeๅๅผๆฅ๏ผllama็codeๅฐฝ้ไธ่ฆๅจ๏ผ่ฎพ่ฎกๅฐdeepseek็ๅฏไปฅๅๅปบๆฐ็ๆไปถ๏ผไฝ้่ฆ้ๆllama็codeใ |
xFasterTransformer | github_2023 | cpp | 274 | intel | changqi1 | @@ -46,5 +48,14 @@ class LlamaRotaryEmbedding {
void llamaCalEmb(const float *inv_freq, const int max_position_embeddings);
private:
- static bool initialized;
+ bool initialized = false; | ้่ฆstatic็๏ผไฝ ่ฟsinๅcosไผๆๅคไปฝ็ธๅ็ๅฎไพ๏ผไฝไธไธชmodelๅช้่ฆไธไปฝsinๅcos |
xFasterTransformer | github_2023 | cpp | 274 | intel | changqi1 | @@ -17,41 +17,48 @@
#include "allocator.h"
#include "compile_util.h"
-static int inv_freq_size = -1;
-static float *emb_cos = nullptr;
-static float *emb_sin = nullptr;
+LlamaRotaryEmbedding::LlamaRotaryEmbedding(DecoderContext *ctx) {
+ const std::string inv_freq_str = "inv_freq";
+ const std::string emb_cos... | ๆLLaMaๅdeepseek็codeๅๅผๆฅ๏ผllama็codeๅฐฝ้ไธ่ฆๅจ๏ผๆถๅๅฐdeepseek็ๅฏไปฅๅๅปบๆฐ็ๆไปถ๏ผไฝ้่ฆ้ๆllama็codeใ่ฟไธชไฝ ๅฏไปฅๆฐๅปบไธไธชdeepseek็ropeๆไปถใ |
xFasterTransformer | github_2023 | python | 274 | intel | changqi1 | @@ -117,7 +117,7 @@ def build_inputs_chatglm(tokenizer, query: List[str], padding, history: List[Tup
model_prompt = prompt_pool["chatglm2"]
if "chatglm3" in args.model_name.lower():
model_prompt = prompt_pool["chatglm3"]
- if "llama" in args.model_name.lower():
+ if "llama" in args.model_na... | ๅ็ฌ if deepseek |
xFasterTransformer | github_2023 | others | 274 | intel | changqi1 | @@ -141,6 +142,7 @@ xFasterTransformer supports a different model format from Huggingface, but it's
Supported model convert list:
- LlamaConvert
+ - DeepseekConvert | put it down |
xFasterTransformer | github_2023 | python | 274 | intel | changqi1 | @@ -34,6 +34,7 @@ def with_mpirun():
"automodel": ["AutoModel"],
"tools": [
"LlamaConvert",
+ "DeepseekConvert", | put it down |
xFasterTransformer | github_2023 | cpp | 278 | intel | pujiang2018 | @@ -0,0 +1,43 @@
+// Copyright (c) 2023 Intel Corporation | let's change to 2024 |
xFasterTransformer | github_2023 | cpp | 278 | intel | pujiang2018 | @@ -0,0 +1,48 @@
+// Copyright (c) 2023 Intel Corporation | let's change to 2024 |
xFasterTransformer | github_2023 | cpp | 278 | intel | pujiang2018 | @@ -0,0 +1,43 @@
+// Copyright (c) 2023 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required... | shall we combine batchSize and seqLen into one parameter? (think about continuous batching, we just need to pass the total id size) |
xFasterTransformer | github_2023 | others | 262 | intel | pujiang2018 | @@ -1,5 +1,34 @@
# CHANGELOG
+# [Version v1.4.0](https://github.com/intel/xFasterTransformer/releases/tag/v1.4.0)
+v1.4.0 - Support fully BF16 inference deployment of Llama series and add serving supports.
+
+## Functionality
+- Introduce pure BF16 support in Llama series models, now can use fully BF16 data type to ... | Since BF16 previously already supported (though not the fully support), suggest to modify it like:
Introduce fully BF16 support in Llama series models to better use AMX |
xFasterTransformer | github_2023 | cpp | 245 | intel | changqi1 | @@ -50,6 +50,8 @@ class MMHelper {
std::cerr << "[Error] Wrong device type." << std::endl;
std::exit(-1);
}
+
+ AMXThresholdM=Env::getAMXThresholdM(); | ็ฉบๆ ผ |
xFasterTransformer | github_2023 | cpp | 252 | intel | pujiang2018 | @@ -0,0 +1,31 @@
+// Copyright (c) 2023 Intel Corporation | let's change to 2024 |
xFasterTransformer | github_2023 | cpp | 224 | intel | pujiang2018 | @@ -170,11 +202,33 @@ inline void float16_t::cvt_float16_to_float(const float16_t *src, float *dst, in
}
}
+inline void float16_t::cvt_float16_to_float_MT(const float16_t *src, float *dst, int size) {
+ // Process 16 floats (AVX512 is a 512-bit SIMD register)
+ constexpr int kStep = 16;
+ int blockSize... | may have risk here. better not change. |
xFasterTransformer | github_2023 | python | 33 | intel | Duyi-Wang | @@ -152,7 +154,7 @@ def build_inputs_chatglm(tokenizer, query: List[str], padding, history: List[Tup
Next_token_throughput = 1000 / latency_90 * args.batch_size
print("\n")
print("=" * 50 + args.model_name + " Final Performance" + "=" * 50)
- print(f"First token Latency:\t{first_token_... | The input token length has been printed in Line 113. |
xFasterTransformer | github_2023 | others | 221 | intel | Duyi-Wang | @@ -14,7 +14,12 @@
# ============================================================================
cmake_minimum_required(VERSION 3.15.1)
+find_package(MPI REQUIRED) | If oneCCL is not present in the user's environment๏ผ |
xFasterTransformer | github_2023 | cpp | 221 | intel | Duyi-Wang | @@ -134,7 +212,14 @@ class CommonDecoder : public AbstractDecoder {
vocabSize, embeddingSize, maxPositions, maxPosEmbed, maxSeqLength, ropeParamsPtr);
// Decoder
- for (int i = 0; i < layers; ++i) {
+ if (layers % ctx->ppSize != 0) {
+ std::cerr << "Warning: layers c... | When layers is not divisible by ppSize, does it mean that a few layers (layers % ppSize) will not be processed? There is a warning but no termination if layers is not divisible by ppSize. |
xFasterTransformer | github_2023 | cpp | 221 | intel | Duyi-Wang | @@ -227,9 +312,19 @@ class CommonDecoder : public AbstractDecoder {
int *positionIds = this->getPositionIds(ids, batchSize, inputSeqLen, step + this->prefixSharing);
t1.release();
+ // if current pipeline parallel stage rank isn't the first stage, should receive previous stage data
+ i... | This will reintroduce the MPI dependency into xft.so. It should be included in comm_helper.so and referenced through messager. |
xFasterTransformer | github_2023 | cpp | 221 | intel | Duyi-Wang | @@ -67,7 +67,28 @@ class Env {
}
}
- static int getVerbose() { return verbose_value(); }
+ static int getVerbose() { return verboseValue(); }
+
+// Pipeline Parallel
+private:
+ static int &pipelineValue() {
+ static int value = 1;
+ return value;
+ }
+
+public:
+ static voi... | Check if MPI_rank is divisible by ppStages? |
xFasterTransformer | github_2023 | cpp | 221 | intel | Duyi-Wang | @@ -46,7 +46,23 @@ std::vector<int> GreedySearch::getNextToken(int *ids, int batchSize, int seqLen)
std::tuple<float *, int, int> result = decoder.forward(ids, dims, this->step++);
- this->nextTokens = search(result);
+ DecoderContext *ctx = decoder.getContext();
+ if (std::get<0>(result) == nullptr) ... | Use messager and comm_helper.so to decouple MPI dependency. |
xFasterTransformer | github_2023 | cpp | 221 | intel | pujiang2018 | @@ -176,16 +201,21 @@ class Messenger {
private:
int size;
int rank;
+ int color; | I don't know if color is a common concept. Is it easy to understand for others? add some comment? |
xFasterTransformer | github_2023 | cpp | 225 | intel | pujiang2018 | @@ -392,7 +396,11 @@ void BeamSearch::searchTopK(std::tuple<float *, int, int> &result) {
std::vector<long unsigned int> recvCount(msgerSize, static_cast<long unsigned int>(batchSize * numBeams));
messenger.allgatherv(maxVal, batchSize * numBeams, recvMax, recvCount);
- float sumVal[batchSize... | Original float "sumVal[batchSize * numBeams] = {0};" should work. |
xFasterTransformer | github_2023 | cpp | 225 | intel | pujiang2018 | @@ -373,7 +373,11 @@ void BeamSearch::searchTopK(std::tuple<float *, int, int> &result) {
// 4. add beam socre. Initialize -1e9 to all beams except the first one
if (msgerSize > 1) {
// Get the maximum value of each beam through all instance
- float maxVal[batchSize * numBeams] = {std::numeric... | I guess the author intended to set all values to lowest float. good fix. |
xFasterTransformer | github_2023 | cpp | 215 | intel | changqi1 | @@ -149,33 +174,68 @@ void QwenRotaryEmbedding::forward(
cur_emb_sin = std::get<1>(value);
}
- // for (size_t i = 0; i < emb_size; i++) {
- // emb[i] = x[i] * emb_cos[position_ids[i % cached_size / dim]][i % dim];
- // int offset = (i % dim + this->inv_freq_size) % dim;
- // floa... | if ๅ else ไธญ็codeๆฏไธๆฏๅฏไปฅ็ปไธๆไธไปฝ๏ผๆ็็ปๅคงๅคๆฐcodeๆฏๅค็จ็๏ผๅนถไธ else ไธญ q_scale[seq] ไนๆฏ 1.0 ๏ผ |
xFasterTransformer | github_2023 | cpp | 215 | intel | changqi1 | @@ -216,46 +277,103 @@ void QwenRotaryEmbedding::forward(
cur_emb_sin = std::get<1>(value);
}
+ if (seqLen + pastKeyLength > maxSeqLength && logn != nullptr) { | if ๅ else ไธญ็codeๆฏไธๆฏๅฏไปฅ็ปไธๆไธไปฝ๏ผๆ็็ปๅคงๅคๆฐcodeๆฏๅค็จ็๏ผๅนถไธ else ไธญ q_scale[seq] ไนๆฏ 1.0 ๏ผ |
xFasterTransformer | github_2023 | cpp | 183 | intel | pujiang2018 | @@ -69,3 +69,26 @@ void repetitionPenaltyLogitsProcess(float penalty, float *logits, int sampleOffs
}
}
}
+
+void stopWordsCheck(std::vector<int> &nextTokenIds, std::vector<std::vector<int>> &stopWordsList,
+ std::vector<std::vector<int>> &stopWordsIndex, std::vector<int> &doneBatch) {
+ for (i... | @Duyi-Wang Do you need openmp for large batch size? |
xFasterTransformer | github_2023 | cpp | 73 | intel | pujiang2018 | @@ -78,7 +78,9 @@ class bfloat16_t {
}
static void cvt_float_to_bfloat16(const float *src, bfloat16_t *dst, int size);
+ static void batch_cvt_float_to_bfloat16(const float *src, bfloat16_t *dst, int size); | @changqi1 Do you accept adding it in bfloat16.h? |
xFasterTransformer | github_2023 | cpp | 73 | intel | pujiang2018 | @@ -39,6 +42,12 @@ class Messenger {
return;
}
+ bf16_enable = (getenv("XFT_ONECCL_BF16") ? atoi(getenv("XFT_ONECCL_BF16")) : 0);
+ if (bf16_enable) {
+ printf("got 'XFT_ONECCL_BF16=%d', enable BF16 dtype comm.\n", bf16_enable);
+ buf_bf16 = new bfloat16_t[MAX... | suggest using aligned_alloc or malloc.
as new will initialize all the data to 0, which is not needed here. |
xFasterTransformer | github_2023 | cpp | 73 | intel | pujiang2018 | @@ -110,7 +123,20 @@ class Messenger {
// From some example code of oneCCL, inplace reducing is supported
template <typename T>
void reduceAdd(T *sendBuf, T *recvBuf, size_t count) {
+ if constexpr (!std::is_same_v<T, float>) {
+ //todo(marvin): Consideration for additional optimization... | what if count > MAX_BF16_BUFFER? |
xFasterTransformer | github_2023 | cpp | 73 | intel | pujiang2018 | @@ -110,7 +123,20 @@ class Messenger {
// From some example code of oneCCL, inplace reducing is supported
template <typename T>
void reduceAdd(T *sendBuf, T *recvBuf, size_t count) {
+ if constexpr (!std::is_same_v<T, float>) {
+ //todo(marvin): Consideration for additional optimization... | Here the code looks like not formatted. |
xFasterTransformer | github_2023 | cpp | 73 | intel | pujiang2018 | @@ -175,7 +201,8 @@ class Messenger {
int size;
int rank;
bool local_ranks_flag;
-
+ bfloat16_t* buf_bf16 = nullptr; | let's initialize it in the constructor to make sure the same style. |
xFasterTransformer | github_2023 | cpp | 73 | intel | changqi1 | @@ -128,6 +130,18 @@ inline void bfloat16_t::cvt_float_to_bfloat16(const float *src, bfloat16_t *dst,
}
}
+inline void bfloat16_t::batch_cvt_float_to_bfloat16(const float *src, bfloat16_t *dst, int count){
+ constexpr int sizePerSplit = 1024; | Maybe use template to define blockSize or use totalSize/totalSystemThreads to define the blockSize. |
xFasterTransformer | github_2023 | cpp | 157 | intel | pujiang2018 | @@ -85,6 +85,11 @@ class CommonDecoder : public AbstractDecoder {
this->prefixSeqLen = 0;
this->prefixSharing = false;
+ // Quantization config
+ const bool quant_decoder_weights = reader.GetBoolean(modelType, "quant_decoder_weights", false); | Shall we also use camelCase to name the params? |
xFasterTransformer | github_2023 | cpp | 157 | intel | pujiang2018 | @@ -475,42 +481,152 @@ class CommonDecoder : public AbstractDecoder {
int qkvSize = qSize + kvSize + kvSize;
#define ALLOC(size, alignment) aligned_alloc((alignment), (size))
- float *qkvWeight = (float *)ALLOC(hiddenSize * qkvSize * sizeof(float), 64);
+ float *qkvWeight = nullptr;
+ i... | remove it? |
xFasterTransformer | github_2023 | cpp | 157 | intel | pujiang2018 | @@ -475,42 +481,152 @@ class CommonDecoder : public AbstractDecoder {
int qkvSize = qSize + kvSize + kvSize;
#define ALLOC(size, alignment) aligned_alloc((alignment), (size))
- float *qkvWeight = (float *)ALLOC(hiddenSize * qkvSize * sizeof(float), 64);
+ float *qkvWeight = nullptr;
+ i... | maybe need to search all the printf to remove it or move it to debug code. |
xFasterTransformer | github_2023 | cpp | 157 | intel | pujiang2018 | @@ -55,35 +55,69 @@ class Decoder {
int getLayerId() { return layerIdx; }
- void setWeights(DecoderContext *ctx, std::vector<float *> ¶ms, bool trans = true) {
- const float *queryWeight = params[0];
- const float *queryBias = params[1];
- const float *keyWeight = params[2];
- ... | I think it is better to change "int type" to "xft::DataType dt". |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.