-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GSProcessing] BERT Tokenizer (#700)
*Issue #, if available:* *Description of changes:* By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. ------------------------------------------------------ Beside implementing the BERT Tokenizer feature - Add etype_featsize dict in graph loader to fix a bug - Add dependency for setuptools that is necessary for emr-serverless run - Reformat the _process_node_feature and _process_edge feature part to process tokenize feature and also allow enough backward compatibilities. Result: - Constructing full mag dataset with tokenize feature for 111 minutes. Refer to the example here: https://github.com/awslabs/graphstorm/blob/main/examples/mag/mag_v0.2.json --------- Co-authored-by: EC2 Default User <[email protected]> Co-authored-by: Theodore Vasiloudis <[email protected]>
- Loading branch information
1 parent
b01ff7b
commit c29bf54
Showing
21 changed files
with
597 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
graphstorm-processing/docker/0.2.2/emr-serverless/Dockerfile.cpu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
ARG ARCH=x86_64 | ||
FROM public.ecr.aws/emr-serverless/spark/emr-6.13.0:20230906-${ARCH} as base | ||
FROM base as runtime | ||
|
||
USER root | ||
ENV PYTHON_VERSION=3.9.18 | ||
|
||
# Python won’t try to write .pyc or .pyo files on the import of source modules | ||
# Force stdin, stdout and stderr to be totally unbuffered. Good for logging | ||
ENV PYTHONDONTWRITEBYTECODE=1 | ||
ENV PYTHONUNBUFFERED=1 | ||
ENV PYTHONIOENCODING=UTF-8 | ||
|
||
# Set up pyenv | ||
ENV PYENV_ROOT="${HOME}/.pyenv" | ||
ENV PATH="${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${PATH}" | ||
ENV PYSPARK_DRIVER_PYTHON=${PYENV_ROOT}/shims/python | ||
ENV PYSPARK_PYTHON=${PYENV_ROOT}/shims/python | ||
|
||
# TODO: These can probably all go to another builder stage? | ||
RUN yum erase -y openssl-devel && \ | ||
yum install -y \ | ||
bzip2-devel\ | ||
gcc \ | ||
git \ | ||
libffi-devel \ | ||
ncurses-devel \ | ||
openssl11-devel \ | ||
readline-devel \ | ||
sqlite-devel \ | ||
sudo \ | ||
xz-devel && \ | ||
rm -rf /var/cache/yum | ||
RUN git clone https://github.com/pyenv/pyenv.git ${PYENV_ROOT} && \ | ||
pyenv install ${PYTHON_VERSION} && \ | ||
pyenv global ${PYTHON_VERSION} | ||
|
||
WORKDIR /usr/lib/spark/code/ | ||
|
||
# Install GSProcessing requirements to pyenv Python | ||
COPY requirements.txt requirements.txt | ||
# Use --mount=type=cache,target=/root/.cache when Buildkit CI issue is fixed: | ||
# https://github.com/moby/buildkit/issues/1512 | ||
RUN pip install -r /usr/lib/spark/code/requirements.txt \ | ||
&& rm -rf /root/.cache | ||
|
||
# GSProcessing codebase | ||
COPY code/ /usr/lib/spark/code/ | ||
|
||
# Install Huggingface model cache if it is necessary | ||
ARG MODEL="" | ||
ENV TRANSFORMERS_CACHE=/home/hadoop/.cache/huggingface/hub | ||
RUN if [ $MODEL == "" ]; then \ | ||
echo "Skip installing model cache"; \ | ||
else \ | ||
echo "Installing model cache for $MODEL" && \ | ||
python3 -c "from transformers import AutoTokenizer; AutoTokenizer.from_pretrained('${MODEL}')"; \ | ||
fi | ||
|
||
FROM runtime AS prod | ||
RUN python -m pip install --no-deps /usr/lib/spark/code/graphstorm_processing-*.whl && \ | ||
rm /usr/lib/spark/code/graphstorm_processing-*.whl && rm -rf /root/.cache | ||
|
||
FROM runtime AS test | ||
RUN python -m pip install --no-deps /usr/lib/spark/code/graphstorm-processing/ && rm -rf /root/.cache | ||
|
||
USER hadoop:hadoop | ||
WORKDIR /home/hadoop |
67 changes: 67 additions & 0 deletions
67
graphstorm-processing/docker/0.2.2/sagemaker/Dockerfile.cpu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# syntax=docker/dockerfile:experimental | ||
FROM 153931337802.dkr.ecr.us-west-2.amazonaws.com/sagemaker-spark-processing:3.4-cpu-py39-v1.0 AS base | ||
|
||
# Python won’t try to write .pyc or .pyo files on the import of source modules | ||
# Force stdin, stdout and stderr to be totally unbuffered. Good for logging | ||
ENV PYTHONDONTWRITEBYTECODE=1 | ||
ENV PYTHONUNBUFFERED=1 | ||
ENV PYTHONIOENCODING=UTF-8 | ||
ENV LANG=C.UTF-8 | ||
ENV LC_ALL=C.UTF-8 | ||
ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib" | ||
ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/conda/lib" | ||
ENV PATH=/opt/conda/bin:$PATH | ||
|
||
# Install GSProcessing requirements to pipenv Python | ||
RUN pipenv install \ | ||
boto3==1.28.38 \ | ||
joblib==1.3.1 \ | ||
mock==5.1.0 \ | ||
pandas==1.3.5 \ | ||
pip==23.1.2 \ | ||
protobuf==3.20.3 \ | ||
psutil==5.9.5 \ | ||
pyarrow==13.0.0 \ | ||
pyspark==3.4.1 \ | ||
scipy==1.11.3 \ | ||
setuptools \ | ||
transformers==4.37.1 \ | ||
spacy==3.6.0 \ | ||
wheel \ | ||
&& rm -rf /root/.cache | ||
# Do a pipenv sync so our base libs are independent from our editable code, making them cacheable | ||
RUN pipenv sync --system && python3 -m spacy download en_core_web_lg \ | ||
&& rm -rf /root/.cache | ||
|
||
# Graphloader codebase | ||
COPY code/ /usr/lib/spark/code/ | ||
WORKDIR /usr/lib/spark/code/ | ||
|
||
# Base container assumes this is the workdir | ||
ENV SPARK_HOME /usr/lib/spark | ||
WORKDIR $SPARK_HOME | ||
|
||
# Ensure our python3 installation is the one used | ||
RUN echo 'alias python3=python3.9' >> ~/.bashrc | ||
|
||
# Install Huggingface model cache if it is necessary | ||
ARG MODEL="" | ||
ENV TRANSFORMERS_CACHE=/root/.cache/huggingface/hub | ||
RUN if [ $MODEL == "" ]; then \ | ||
echo "Skip installing model cache"; \ | ||
else \ | ||
echo "Installing model cache for $MODEL" && \ | ||
python3 -c "from transformers import AutoTokenizer; AutoTokenizer.from_pretrained('${MODEL}')"; \ | ||
fi | ||
|
||
# Starts framework | ||
ENTRYPOINT ["bash", "/usr/lib/spark/code/docker-entry.sh"] | ||
|
||
FROM base AS prod | ||
RUN python3 -m pip install /usr/lib/spark/code/graphstorm_processing-*.whl && \ | ||
rm /usr/lib/spark/code/graphstorm_processing-*.whl | ||
CMD ["gs-processing"] | ||
|
||
FROM base AS test | ||
RUN python3 -m pip install /usr/lib/spark/code/graphstorm-processing/ | ||
CMD ["sh", "-c", "pytest ./code/tests/"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
graphstorm-processing/graphstorm_processing/config/hf_configs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
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 by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
from typing import Mapping | ||
|
||
from graphstorm_processing.constants import HUGGINGFACE_TOKENIZE | ||
from .feature_config_base import FeatureConfig | ||
|
||
|
||
class HFConfig(FeatureConfig): | ||
"""Feature configuration for huggingface text features. | ||
Supported kwargs | ||
---------------- | ||
action: str, required | ||
The type of huggingface action to use. Valid values is "tokenize_hf" | ||
bert_model: str, required | ||
The name of the lm model. | ||
max_seq_length: int, required | ||
The maximal length of the tokenization results. | ||
""" | ||
|
||
def __init__(self, config: Mapping): | ||
super().__init__(config) | ||
self.action = self._transformation_kwargs.get("action") | ||
self.bert_model = self._transformation_kwargs.get("bert_model") | ||
self.max_seq_length = self._transformation_kwargs.get("max_seq_length") | ||
|
||
self._sanity_check() | ||
|
||
def _sanity_check(self) -> None: | ||
super()._sanity_check() | ||
assert self.action in [ | ||
HUGGINGFACE_TOKENIZE | ||
], f"huggingface action needs to be {HUGGINGFACE_TOKENIZE}" | ||
assert isinstance( | ||
self.bert_model, str | ||
), f"Expect bert_model to be a string, but got {self.bert_model}" | ||
assert ( | ||
isinstance(self.max_seq_length, int) and self.max_seq_length > 0 | ||
), f"Expect max_seq_length {self.max_seq_length} be an integer and larger than zero." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.