{
  "id": 339897,
  "title": "Pre tokenization or tokenize on the fly",
  "url": "/competitions/AI4Code/discussion/339897",
  "author_name": "",
  "post_date": "2022-07-26T15:37:59.722201200Z",
  "votes": 9,
  "comment_count": 8,
  "views": 0,
  "content": "<p>Has anyone tested if the two have much difference on infering speed? Thanks!<br>\nI'm using tokeization on the fly and seems changing to pre seg needs big effort not sure if it could help.</p>",
  "messages": [
    {
      "id": "1872007",
      "postDate": "07/26/2022 15:37:59",
      "content": "<p>Has anyone tested if the two have much difference on infering speed? Thanks!<br>\nI'm using tokeization on the fly and seems changing to pre seg needs big effort not sure if it could help.</p>",
      "rawMarkdown": "Has anyone tested if the two have much difference on infering speed? Thanks!\nI'm using tokeization on the fly and seems changing to pre seg needs big effort not sure if it could help.",
      "votes": null
    },
    {
      "id": "1872144",
      "postDate": "07/26/2022 17:42:04",
      "content": "<p>My observation. Tokenization is insanely fast. I didnt find any significant benefit in pre-tokenizing (during training). In fact, in the popular code of point-wise model, the tokenization is done for the context (ie each of the 20 code cells) for each single markup, so there is lot of duplication. I moved the code tokenization to the dataset initialize function, thinking I will save a good amount of time but it didnt make any noticeable difference of even few seconds. In fact I pre-tokenized the whole thing (code+markdown) and even that barely gave a 1% improvement to the training speed. </p>",
      "rawMarkdown": "My observation. Tokenization is insanely fast. I didnt find any significant benefit in pre-tokenizing (during training). In fact, in the popular code of point-wise model, the tokenization is done for the context (ie each of the 20 code cells) for each single markup, so there is lot of duplication. I moved the code tokenization to the dataset initialize function, thinking I will save a good amount of time but it didnt make any noticeable difference of even few seconds. In fact I pre-tokenized the whole thing (code+markdown) and even that barely gave a 1% improvement to the training speed.",
      "votes": null
    },
    {
      "id": "1872315",
      "postDate": "07/26/2022 20:08:49",
      "content": "<p>Thanks so much <a href=\"https://www.kaggle.com/allohvk\" target=\"_blank\">@allohvk</a> , your advice is great!</p>",
      "rawMarkdown": "Thanks so much @allohvk , your advice is great!",
      "votes": null
    },
    {
      "id": "1874250",
      "postDate": "07/28/2022 06:53:22",
      "content": "<p>Thanks for your kind words <a href=\"https://www.kaggle.com/goldenlock\" target=\"_blank\">@goldenlock</a> . Kindly note that my experience was more on the training aspect. Perhapes if you have huge set of more than dozen models and you have to repeat tokenization again and again during inference time, maybe there \"could\" be slight improvement by doing it only once. Secondly when I mention tokenization, I dont consider pre-processing as part of that. So cleaning/preprocessing can be done beforehand and there maybe some benefits to doing that at during dataset initialization and not at runtime. Of course you may be aware of all this but just documenting the same for the benefit of the larger community in case this is useful to someone. <br>\nAlso speaking of tokenization speed, one minor irritant that sooner or later one is bound to run into is the following tokenizer parallelization error/warning for which below SOF post may be helpful to the readers… <a href=\"https://stackoverflow.com/questions/62691279/how-to-disable-tokenizers-parallelism-true-false-warning/72926996#72926996\" target=\"_blank\">https://stackoverflow.com/questions/62691279/how-to-disable-tokenizers-parallelism-true-false-warning/72926996#72926996</a></p>",
      "rawMarkdown": "Thanks for your kind words @goldenlock . Kindly note that my experience was more on the training aspect. Perhapes if you have huge set of more than dozen models and you have to repeat tokenization again and again during inference time, maybe there \"could\" be slight improvement by doing it only once. Secondly when I mention tokenization, I dont consider pre-processing as part of that. So cleaning/preprocessing can be done beforehand and there maybe some benefits to doing that at during dataset initialization and not at runtime. Of course you may be aware of all this but just documenting the same for the benefit of the larger community in case this is useful to someone. \nAlso speaking of tokenization speed, one minor irritant that sooner or later one is bound to run into is the following tokenizer parallelization error/warning for which below SOF post may be helpful to the readers... https://stackoverflow.com/questions/62691279/how-to-disable-tokenizers-parallelism-true-false-warning/72926996#72926996",
      "votes": null
    },
    {
      "id": "1875402",
      "postDate": "07/29/2022 02:05:45",
      "content": "<p>did quite similar thing and no big change of speed or accuracy change when performing cleaning/pre-tokenization to code and markdown cells. Also, if possible, would like to know how could you achieve 90%+! I tried 20+ models and still far away from it. any type of hints are welcome~~</p>",
      "rawMarkdown": "did quite similar thing and no big change of speed or accuracy change when performing cleaning/pre-tokenization to code and markdown cells. Also, if possible, would like to know how could you achieve 90%+! I tried 20+ models and still far away from it. any type of hints are welcome~~",
      "votes": null
    },
    {
      "id": "1875575",
      "postDate": "07/29/2022 05:53:50",
      "content": "<p>also, if you use amp (fp16) (an easy way is based on pytorch_lightning), it can give some speed up so that more models can be ensembled. (the maximum hours was 8 around currently; 10 hours will fail the time-checking)</p>",
      "rawMarkdown": "also, if you use amp (fp16) (an easy way is based on pytorch_lightning), it can give some speed up so that more models can be ensembled. (the maximum hours was 8 around currently; 10 hours will fail the time-checking)",
      "votes": null
    },
    {
      "id": "1875891",
      "postDate": "07/29/2022 11:49:16",
      "content": "<p><a href=\"https://www.kaggle.com/xianchaowu\" target=\"_blank\">@xianchaowu</a> Thanks! I was thought amp could not speedup on kaggle's old gpu. I will have a try!<br>\nFor the competition I'm using heavy model based on excellent open code solutions, I will share more after close.</p>",
      "rawMarkdown": "xianchaowu Thanks! I was thought amp could not speedup on kaggle's old gpu. I will have a try!\nFor the competition I'm using heavy model based on excellent open code solutions, I will share more after close.",
      "votes": null
    },
    {
      "id": "1876540",
      "postDate": "07/29/2022 20:34:14",
      "content": "<p><a href=\"https://www.kaggle.com/goldenlock\" target=\"_blank\">@goldenlock</a> so nice of you</p>",
      "rawMarkdown": "goldenlock so nice of you~~~ really appreciate and looking forward to learning more from the future nice solution sharing~~",
      "votes": null
    },
    {
      "id": "1877571",
      "postDate": "07/30/2022 19:33:51",
      "content": "<p>pre tokenization can make a difference if you reuse it. For instance for training for more than one epoch. But for inference I don't really see what you would gain.</p>",
      "rawMarkdown": "pre tokenization can make a difference if you reuse it. For instance for training for more than one epoch. But for inference I don't really see what you would gain.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1872144,
      "author_name": "allohvk",
      "author_url": "",
      "post_date": "07/26/2022 17:42:04",
      "content": "<p>My observation. Tokenization is insanely fast. I didnt find any significant benefit in pre-tokenizing (during training). In fact, in the popular code of point-wise model, the tokenization is done for the context (ie each of the 20 code cells) for each single markup, so there is lot of duplication. I moved the code tokenization to the dataset initialize function, thinking I will save a good amount of time but it didnt make any noticeable difference of even few seconds. In fact I pre-tokenized the whole thing (code+markdown) and even that barely gave a 1% improvement to the training speed. </p>",
      "votes": null,
      "replies": [
        {
          "id": 1872315,
          "author_name": "goldenlock",
          "author_url": "",
          "post_date": "07/26/2022 20:08:49",
          "content": "<p>Thanks so much <a href=\"https://www.kaggle.com/allohvk\" target=\"_blank\">@allohvk</a> , your advice is great!</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1874250,
          "author_name": "allohvk",
          "author_url": "",
          "post_date": "07/28/2022 06:53:22",
          "content": "<p>Thanks for your kind words <a href=\"https://www.kaggle.com/goldenlock\" target=\"_blank\">@goldenlock</a> . Kindly note that my experience was more on the training aspect. Perhapes if you have huge set of more than dozen models and you have to repeat tokenization again and again during inference time, maybe there \"could\" be slight improvement by doing it only once. Secondly when I mention tokenization, I dont consider pre-processing as part of that. So cleaning/preprocessing can be done beforehand and there maybe some benefits to doing that at during dataset initialization and not at runtime. Of course you may be aware of all this but just documenting the same for the benefit of the larger community in case this is useful to someone. <br>\nAlso speaking of tokenization speed, one minor irritant that sooner or later one is bound to run into is the following tokenizer parallelization error/warning for which below SOF post may be helpful to the readers… <a href=\"https://stackoverflow.com/questions/62691279/how-to-disable-tokenizers-parallelism-true-false-warning/72926996#72926996\" target=\"_blank\">https://stackoverflow.com/questions/62691279/how-to-disable-tokenizers-parallelism-true-false-warning/72926996#72926996</a></p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1875402,
      "author_name": "xianchaowu",
      "author_url": "",
      "post_date": "07/29/2022 02:05:45",
      "content": "<p>did quite similar thing and no big change of speed or accuracy change when performing cleaning/pre-tokenization to code and markdown cells. Also, if possible, would like to know how could you achieve 90%+! I tried 20+ models and still far away from it. any type of hints are welcome~~</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1875575,
      "author_name": "xianchaowu",
      "author_url": "",
      "post_date": "07/29/2022 05:53:50",
      "content": "<p>also, if you use amp (fp16) (an easy way is based on pytorch_lightning), it can give some speed up so that more models can be ensembled. (the maximum hours was 8 around currently; 10 hours will fail the time-checking)</p>",
      "votes": null,
      "replies": [
        {
          "id": 1875891,
          "author_name": "goldenlock",
          "author_url": "",
          "post_date": "07/29/2022 11:49:16",
          "content": "<p><a href=\"https://www.kaggle.com/xianchaowu\" target=\"_blank\">@xianchaowu</a> Thanks! I was thought amp could not speedup on kaggle's old gpu. I will have a try!<br>\nFor the competition I'm using heavy model based on excellent open code solutions, I will share more after close.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1876540,
      "author_name": "xianchaowu",
      "author_url": "",
      "post_date": "07/29/2022 20:34:14",
      "content": "<p><a href=\"https://www.kaggle.com/goldenlock\" target=\"_blank\">@goldenlock</a> so nice of you</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1877571,
      "author_name": "cpmpml",
      "author_url": "",
      "post_date": "07/30/2022 19:33:51",
      "content": "<p>pre tokenization can make a difference if you reuse it. For instance for training for more than one epoch. But for inference I don't really see what you would gain.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1872007": "Has anyone tested if the two have much difference on infering speed? Thanks!\nI'm using tokeization on the fly and seems changing to pre seg needs big effort not sure if it could help.",
    "1872144": "My observation. Tokenization is insanely fast. I didnt find any significant benefit in pre-tokenizing (during training). In fact, in the popular code of point-wise model, the tokenization is done for the context (ie each of the 20 code cells) for each single markup, so there is lot of duplication. I moved the code tokenization to the dataset initialize function, thinking I will save a good amount of time but it didnt make any noticeable difference of even few seconds. In fact I pre-tokenized the whole thing (code+markdown) and even that barely gave a 1% improvement to the training speed.",
    "1872315": "Thanks so much @allohvk , your advice is great!",
    "1874250": "Thanks for your kind words @goldenlock . Kindly note that my experience was more on the training aspect. Perhapes if you have huge set of more than dozen models and you have to repeat tokenization again and again during inference time, maybe there \"could\" be slight improvement by doing it only once. Secondly when I mention tokenization, I dont consider pre-processing as part of that. So cleaning/preprocessing can be done beforehand and there maybe some benefits to doing that at during dataset initialization and not at runtime. Of course you may be aware of all this but just documenting the same for the benefit of the larger community in case this is useful to someone. \nAlso speaking of tokenization speed, one minor irritant that sooner or later one is bound to run into is the following tokenizer parallelization error/warning for which below SOF post may be helpful to the readers... https://stackoverflow.com/questions/62691279/how-to-disable-tokenizers-parallelism-true-false-warning/72926996#72926996",
    "1875402": "did quite similar thing and no big change of speed or accuracy change when performing cleaning/pre-tokenization to code and markdown cells. Also, if possible, would like to know how could you achieve 90%+! I tried 20+ models and still far away from it. any type of hints are welcome~~",
    "1875575": "also, if you use amp (fp16) (an easy way is based on pytorch_lightning), it can give some speed up so that more models can be ensembled. (the maximum hours was 8 around currently; 10 hours will fail the time-checking)",
    "1875891": "xianchaowu Thanks! I was thought amp could not speedup on kaggle's old gpu. I will have a try!\nFor the competition I'm using heavy model based on excellent open code solutions, I will share more after close.",
    "1876540": "goldenlock so nice of you~~~ really appreciate and looking forward to learning more from the future nice solution sharing~~",
    "1877571": "pre tokenization can make a difference if you reuse it. For instance for training for more than one epoch. But for inference I don't really see what you would gain."
  },
  "source": "meta"
}