https://github.com/amazon-science/alexa-teacher-models

https://github.com/amazon-science/alexa-teacher-models

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.1%) to scientific vocabulary
Last synced: 11 months ago · JSON representation

Repository

Basic Info
  • Host: GitHub
  • Owner: amazon-science
  • License: apache-2.0
  • Language: Python
  • Default Branch: main
  • Size: 1.42 MB
Statistics
  • Stars: 362
  • Watchers: 36
  • Forks: 27
  • Open Issues: 3
  • Releases: 2
Created almost 4 years ago · Last pushed over 1 year ago
Metadata Files
Readme Contributing License Code of conduct

README.md

Alexa Teacher Models

This is the official Alexa Teacher Model program github page.

AlexaTM 20B

AlexaTM 20B is a 20B-Parameter sequence-to-sequence transformer model created by the Alexa Teacher Model (AlexaTM) team at Amazon. The model was trained on a mixture of Common Crawl (mC4) and Wikipedia data across 12 languages using denoising and Causal Language Modeling (CLM) tasks.

AlexaTM 20B can be used for in-context learning. "In-context learning," also known as "prompting," refers to a method for using NLP models in which no fine tuning is required per task. Training examples are provided to the model only as part of the prompt given as inference input, a paradigm known as "few-shot in-context learning." In some cases, the model can perform well without any training data at all, a paradigm known as "zero-shot in-context learning."

To learn more about the model, please read the Amazon Science blog post and the paper.

The model is currently available for noncommercial use via SageMaker JumpStart, as described in our AWS blog post. The model can be accessed using the following steps:

  1. Create an AWS account if needed.
  2. In your AWS account, search for SageMaker in the search bar and click on it.
  3. Once in the SageMaker experience, create a domain and a studio user if none yet exist. All of the default settings can be used.
  4. In the control panel, click Launch app next to the user you wish to use. Launch a studio instance.
  5. Once in the studio, there will be a launcher showing JumpStart as one of the tiles. Click Go to SageMaker Jumpstart. Alternatively, JumpStart can be accessed by 3-pointed orange symbol on the far left of the studio.
  6. Once in JumpStart, click the Notebooks button.
  7. Browse or search for our example notebook entitled In-context learning with AlexaTM 20B.
  8. There will be a button at the top to copy the read-only version into your studio.
  9. Ensure that your kernel has started, and run the notebook.

Note: You can also find our example notebook here

Load the Model and Run Inference

```python from alexateachermodels import AlexaTMTokenizerFast tokenizer = AlexaTMTokenizerFast.from_pretrained('/path/to/AlexaTM-20B-pr/')

Load the model

from alexateachermodels import AlexaTMSeq2SeqForConditionalGeneration model = AlexaTMSeq2SeqForConditionalGeneration.from_pretrained('/path/to/AlexaTM-20B-pr/') ```

You can also use the AutoTokenizer and AutoModelForSeq2SeqLM as you would in any other HuggingFace Transformer program by importing alexa_teacher_models:

```python import alexateachermodels ... tokenizer = AutoTokenizer.frompretrained('/path/to/AlexaTM-20B-pr/') model = AutoModelForSeq2SeqLM.frompretrained('/path/to/AlexaTM-20B-pr/')

```

Load the model on 4 gpus:

python model.bfloat16() model.parallelize(4)

Run the model in CLM mode: ```python

qa

test = """[CLM] Question: Who is the vocalist of coldplay? Answer:""" print('Input:', test) encoded = tokenizer(test, returntensors="pt").to('cuda:0') generatedtokens = model.generate(inputids=encoded['inputids'], maxlength=32, numbeams=1, numreturnsequences=1, earlystopping=True) tokenizer.batchdecode(generatedtokens, skipspecial_tokens=True)[0] ```

Run the model in denoising mode: ```python

denoising

test = "we went to which is the capital of France" print('Input:', test) encoded = tokenizer(test, returntensors="pt").to('cuda:0') generatedtokens = model.generate(inputids=encoded['inputids'], maxlength=32, numbeams=5, numreturnsequences=5, earlystopping=True) tokenizer.batchdecode(generatedtokens, skipspecial_tokens=True) ```

Running the repl example

A sample Read Execute Print Loop (REPL) program is provided in the samples. It can be used to interact with any AlexaTM model, and has a flexible set of command line arguments, including support for sampling and using multiple turns of history as context

``` $ pip install alexateachermodels[repl] $ python -m alexateachermodels.scripts.repl --model /path/to/AlexaTM-20B-pr/ --maxlength 64 $ python -m alexateachermodels.scripts.repl --model /path/to/AlexaTM-20B-pr/ --maxlength 64 --dosample --maxhistory 3 --join_string " "

```

Fine-tuning with DeepSpeed on a single P4

Note We strongly recommend training on multiple instances. For information on how to do this, see the section below

To run on a single P4 (8 GPUs), you will need to use CPU offload. A deepspeed config is provided in the scripts/deepspeed directory. Assuming you have a training and validation JSONL formatted file, a run would look like this: ``` $ pip install alexateachermodels[ft] $ deepspeed --numgpus 8 --module alexateachermodels.scripts.finetune --perdevicetrainbatchsize $BS \ --deepspeed deepspeed/zero3-offload.json \ --modelnameorpath /home/ubuntu/AlexaTM/ --maxlength 512 --bf16 --outputdir output \ --maxtargetlength 64 --dotrain --learningrate 1e-7 \ --trainfile train.json --validationfile valid.json \ --numtrainepochs 1 --save_steps 1000

```

Fine-tuning with DeepSpeed on multiple machines

There is a detailed tutorial demonstrating how to fine-tune 20B across multiple machines in EC2 using Elastic Fabric Adapter (EFA).

Citation

If you use AlexaTM 20B, please use the following BibTeX entry.

@article{soltan2022alexatm, title={AlexaTM 20B: Few-Shot Learning Using a Large-Scale Multilingual Seq2seq Model}, author={Saleh Soltan, Shankar Ananthakrishnan, Jack FitzGerald, Rahul Gupta, Wael Hamza, Haidar Khan, Charith Peris, Stephen Rawls, Andy Rosenbaum, Anna Rumshisky, Chandana Satya Prakash, Mukund Sridhar, Fabian Triefenbach, Apurv Verma, Gokhan Tur, Prem Natarajan}, year={2022} }

Security

See CONTRIBUTING for more information.

License

The code in this package is subject to License. However, the model weights are subject to Model License.

Owner

  • Name: Amazon Science
  • Login: amazon-science
  • Kind: organization

GitHub Events

Total
  • Watch event: 1
  • Push event: 1
  • Fork event: 1
Last Year
  • Watch event: 1
  • Push event: 1
  • Fork event: 1

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 14
  • Total Committers: 5
  • Avg Commits per committer: 2.8
  • Development Distribution Score (DDS): 0.714
Past Year
  • Commits: 1
  • Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Jack FitzGerald (jgmf) j****f@a****m 4
Daniel Pressel d****l@g****m 4
Daniel Pressel d****p@a****m 4
Saleh Soltan s****n@a****m 1
Amazon GitHub Automation 5****o 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 9
  • Total pull requests: 9
  • Average time to close issues: 8 days
  • Average time to close pull requests: about 6 hours
  • Total issue authors: 4
  • Total pull request authors: 2
  • Average comments per issue: 3.56
  • Average comments per pull request: 0.0
  • Merged pull requests: 8
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • JPhilipp (3)
  • ieee8023 (2)
  • philschmid (1)
  • mayank31398 (1)
Pull Request Authors
  • dpressel (8)
  • ssoltan88 (1)
Top Labels
Issue Labels
Pull Request Labels

Dependencies

.github/workflows/pypi.yml actions
  • actions/checkout v1 composite
  • actions/setup-python v1 composite
  • pypa/gh-action-pypi-publish release/v1 composite
pyproject.toml pypi
setup.py pypi