DeepSpeed icon indicating copy to clipboard operation
DeepSpeed copied to clipboard

[BUG] Hybrid Engine with DeepSpeed Stage 3 results and Llama V2 results in gibberish outputs

Open pacman100 opened this issue 2 years ago • 2 comments

Describe the bug Hybrid Engine with DeepSpeed Stage 3 results and Llama V2 results in gibberish outputs

Log output

------------------------------------------------------
accelerator.process_index=0 ['<s> [INST] Explain Deep Learning like a Pirate. [/INST]\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n']
----------------------------------------------------------------------------------------------------
accelerator.process_index=1 ['<s> [INST] Explain Deep Learning like a Pirate. [/INST]\n.\n\n................\n\n.\n................\n.\n.\n.\n.\n........\n.\n.\n.\n......\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.']
----------------------------------------------------------------------------------------------------

To Reproduce Steps to reproduce the behavior:

  1. Code he_ds_test.py:
from accelerate import Accelerator, DeepSpeedPlugin
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from torch.distributed.fsdp.fully_sharded_data_parallel import FullyShardedDataParallel as FSDP
import contextlib
import math

MODEL_NAME = "meta-llama/Llama-2-7b-chat-hf"  #"HuggingFaceH4/zephyr-7b-beta"


def main():
    accelerator = Accelerator()
    
    
    tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
    tokenizer.add_special_tokens({'pad_token': '[PAD]'})
    tokenizer.padding_side = 'right'

    model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
    model.config.eos_token_id = tokenizer.eos_token_id
    model.config.pad_token_id = tokenizer.pad_token_id
    model.resize_token_embeddings(int(8 * math.ceil(len(tokenizer) / 8.0)))  # make the vocab size multiple of 8

    optimizer = torch.optim.Adam(model.parameters(), lr=5e-5)
    
    model, optimizer = accelerator.prepare(model, optimizer)
    
    model.eval()
    print(model)
    sample_texts = [
    [{"role": "user", "content": "Explain Deep Learning like a Pirate."}],
    [{"role": "user", "content": "Why is it important to eat socks daily?"}],
    [{"role": "user", "content": "Write a tweet about the latest model by Google Gemini which is topping all the benchmarks"}],
    [{"role": "user", "content": "How do I convert a Python dictionary into a string representation?"}]     
    ]
    for i in range(len(sample_texts)):
        sample_texts[i] = tokenizer.apply_chat_template(sample_texts[i], add_generation_prompt=True, tokenize=False)

    accelerator.print(sample_texts)
    inputs = tokenizer(sample_texts[0], return_tensors="pt", padding=True, add_special_tokens=False).to(accelerator.device)
    
    unwrapped_model = accelerator.unwrap_model(model)
    outputs = unwrapped_model.generate(**inputs, 
                                       eos_token_id=tokenizer.eos_token_id,
                                       pad_token_id=tokenizer.pad_token_id,
                                       synced_gpus=True,
                                       max_new_tokens=128,
                                       do_sample=False,
                                       # temperature=0.2, 
                                       # top_p=0.95, 
                                      )
    print(f"{accelerator.process_index=} {tokenizer.batch_decode(outputs, skip_special_tokens=False)}")
    print("".join(["-"]*100))


if __name__ == "__main__":
    main()
  1. DeepSpeed config config.json:
{
    "fp16": {
        "enabled": true
    },
    "zero_optimization": {
        "stage": 3
    },
    "hybrid_engine": {
            "enabled": true
    },
    "train_micro_batch_size_per_gpu": 1
}

  1. Accelerate config ds.yaml:
compute_environment: LOCAL_MACHINE
debug: false
deepspeed_config:
  deepspeed_config_file: config.json
  zero3_init_flag: true
distributed_type: DEEPSPEED
downcast_bf16: 'no'
machine_rank: 0
main_training_function: main
num_machines: 1
num_processes: 2
rdzv_backend: static
same_network: true
tpu_env: []
tpu_use_cluster: false
tpu_use_sudo: false
use_cpu: false
  1. Command to run:
accelerate launch --config_file ds.yaml he_ds_test.py
  1. Run the above command on 1 A100 80GB GPUs.

Expected behavior The outputs should follow the given instruction and provide correct answer in the expected style/tone.

ds_report output

--------------------------------------------------
DeepSpeed C++/CUDA extension op report
--------------------------------------------------
NOTE: Ops not installed will be just-in-time (JIT) compiled at
      runtime if needed. Op compatibility means that your system
      meet the required dependencies to JIT install the op.
--------------------------------------------------
JIT compiled ops requires ninja
ninja .................. [OKAY]
--------------------------------------------------
op name ................ installed .. compatible
--------------------------------------------------
 [WARNING]  async_io requires the dev libaio .so object and headers but these were not found.
 [WARNING]  async_io: please install the libaio-dev package with apt
 [WARNING]  If libaio is already installed (perhaps from source), try setting the CFLAGS and LDFLAGS environment variables to where it can be found.
async_io ............... [NO] ....... [NO]
fused_adam ............. [NO] ....... [OKAY]
cpu_adam ............... [NO] ....... [OKAY]
cpu_adagrad ............ [NO] ....... [OKAY]
cpu_lion ............... [NO] ....... [OKAY]
 [WARNING]  Please specify the CUTLASS repo directory as environment variable $CUTLASS_PATH
evoformer_attn ......... [NO] ....... [NO]
fused_lamb ............. [NO] ....... [OKAY]
fused_lion ............. [NO] ....... [OKAY]
inference_core_ops ..... [NO] ....... [OKAY]
cutlass_ops ............ [NO] ....... [OKAY]
quantizer .............. [NO] ....... [OKAY]
ragged_device_ops ...... [NO] ....... [OKAY]
ragged_ops ............. [NO] ....... [OKAY]
random_ltd ............. [NO] ....... [OKAY]
 [WARNING]  sparse_attn requires a torch version >= 1.5 and < 2.0 but detected 2.1
 [WARNING]  using untested triton version (2.1.0), only 1.0.0 is known to be compatible
sparse_attn ............ [NO] ....... [NO]
spatial_inference ...... [NO] ....... [OKAY]
transformer ............ [NO] ....... [OKAY]
stochastic_transformer . [NO] ....... [OKAY]
transformer_inference .. [NO] ....... [OKAY]
--------------------------------------------------
DeepSpeed general environment info:
torch install path ............... ['/raid/sourab/miniconda3/envs/hf/lib/python3.10/site-packages/torch']
torch version .................... 2.1.0+cu121
deepspeed install path ........... ['/raid/sourab/miniconda3/envs/hf/lib/python3.10/site-packages/deepspeed']
deepspeed info ................... 0.12.4, unknown, unknown
torch cuda version ............... 12.1
torch hip version ................ None
nvcc version ..................... 12.1
deepspeed wheel compiled w. ...... torch 2.1, cuda 12.1
shared memory (/dev/shm) size .... 251.77 GB

System info (please complete the following information):

  • OS: [e.g. Ubuntu 22.04]
  • GPU count and types [e.g. one machines with x4 A100s each]
  • (if applicable) what DeepSpeed-MII version are you using
  • (if applicable) Hugging Face Transformers 4.36.0.dev0, Accelerate 0.25.0.dev0
  • Python version 3.10.13

pacman100 avatar Dec 08 '23 15:12 pacman100

I made some changes to the code to make the lm_head and token_emb weight the right shape, but the hybrid engine still generate gibberish words.

def main():
    accelerator = Accelerator()
    tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
    tokenizer.pad_token = tokenizer.unk_token
    tokenizer.padding_side = 'left'
    # -------------------------- --------------------------
with output: <s> [INST] Explain Deep Learning like a Pirate. [/INST]\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n]

rbao2018 avatar Dec 27 '23 13:12 rbao2018

Hello, any updates on this?

pacman100 avatar Apr 12 '24 11:04 pacman100