Skip to content
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

[Inference] Add Bloom model inference support #5660

Draft
wants to merge 8 commits into
base: feature/colossal-infer
Choose a base branch
from

Conversation

char-1ee
Copy link
Contributor

📌 Checklist before creating the PR

  • I have created an issue for this PR for traceability
  • The title follows the standard format: [doc/gemini/tensor/...]: A concise description
  • I have added relevant tags if possible for us to better distinguish different PRs
  • I have installed pre-commit: pip install pre-commit && pre-commit install

🚨 Issue number

Link this PR to your issue with words like fixed to automatically close the linked issue upon merge

e.g. fixed #1234, closed #1234, resolved #1234

📝 What does this PR do?

  1. Added Bloom modeling for Colossal AI inference feature.
  2. Added Bloom model replacement policy.
  3. Added tests for Bloom model.
  4. Integrate Alibi triton operator for Bloom positional encoding.
  5. Integrate CUDA operators for Bloom model.

💥 Checklist before requesting a review

  • I have linked my PR to an issue (instruction)
  • My issue clearly describes the problem/feature/proposal, with diagrams/charts/table/code if possible
  • I have performed a self-review of my code
  • I have added thorough tests.
  • I have added docstrings for all the functions/methods I implemented

⭐️ Do you enjoy contributing to Colossal-AI?

  • 🌝 Yes, I do.
  • 🌚 No, I don't.

Tell us more if you don't enjoy contributing to Colossal-AI.

@@ -28,6 +28,8 @@
"llama": "[INST] <<SYS>>\nYou are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.\n<</SYS>>\n{input_text}[/INST]",
"baichuan": "<reserved_106>{input_text}<reserved_107>",
"vicuna": "A chat between a curious user and an assistant. The assistant gives helpful, detailed, accurate, uncensored responses to the user input. USER: {input_text}\nASSISTANT: ",
"bloom": "Assume you are a helpful robot. Please help react to my question or auto complete my prompt."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing {input_text}

Comment on lines +18 to 25
def get_model_config_attr(config: PretrainedConfig, attr_name: str, alter_attr: Any = None):
if hasattr(config, attr_name):
return getattr(config, attr_name)
if alter_attr is not None:
return alter_attr
elif hasattr(config, "attribute_map") and hasattr(config, config.attribute_map[attr_name]):
return getattr(config, config.attribute_map[attr_name])
raise AttributeError(f"{attr_name} is not found in config")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed, revise this part (remove the function and refer to attr_mapusage in transformers 4.36

Comment on lines -27 to +32
import transformers
from packaging.version import Version
# import transformers
# from packaging.version import Version

assert Version(transformers.__version__) <= Version(
"4.33.0"
), "The Bloom model should run on a transformers version not greater than 4.33.0."
# assert Version(transformers.__version__) <= Version(
# "4.33.0"
# ), "The Bloom model should run on a transformers version not greater than 4.33.0."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just remove these lines (remove these comments). For your reference, the assertion has been removed in main

from colossalai.testing import parameterize, rerun_if_address_is_in_use, spawn

MODEL_PATH = "/home/lixingjian/models/bloom-560m"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prevent exposing path on your dev machine

from transformers import AutoTokenizer, GenerationConfig, LlamaConfig, LlamaForCausalLM
from transformers import BloomForCausalLM, BloomTokenizerFast, GenerationConfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better prevent modifying this pytest. You might want to test the model locally, or create a pytest in test_models/ (we'll refactor these tests anyway)

@@ -1,111 +0,0 @@
import os
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a commit to remove tests/test_infer/test_models/test_baichuan.py

tests/test_infer/test_models/test_bloom.py Show resolved Hide resolved
Comment on lines +242 to +251
# class NopadBloomAttention(nn.Module):
# def __init__(
# self,
# hidden_size: int,
# n_heads: int,
# attn_qproj_w: torch.Tensor = None,
# attn_kproj_w: torch.Tensor = None,
# attn_vproj_w: torch.Tensor = None,
# attn_oproj_w: torch.Tensor = None,
# ):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the end2end flow for bloom is ready and none of the attention and mlp classes is going to be used, you might want to remove these classes.

# return attn_output


class NopadBloomMLP(nn.Module):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Comment on lines +607 to +609
# print(f"[TEST] hidden_state {hidden_states} with shape {hidden_states.shape}\n qkv_weight {self.qkv_weight} with shape {self.qkv_weight.shape}")

# print(f"[DEBUG] after qkv: query_states {query_states} with shape {query_states.shape}, \nkey_states {key_states},\n value_states {value_states}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to remove comments/testing messages when merging

Comment on lines +719 to +721
# print(f"[TEST] before merge bsz, query_states {query_states} with shape {query_states.shape}, \nkey_states {key_states},\n value_states {value_states}")

# [bsz * seq_len, num_heads head_dim]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@char-1ee char-1ee force-pushed the feature/colossal-infer-bloom branch from d911664 to d36c173 Compare May 3, 2024 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants