- 
                Notifications
    You must be signed in to change notification settings 
- Fork 37
Support of generate #261
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
          
     Merged
      
      
    
  
     Merged
                    Support of generate #261
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            20 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      a46d581
              
                copy from denis/generate of only generate support part, with some chaβ¦
              
              
                bigximik 9a81f89
              
                fix to use right config param
              
              
                bigximik 667aacf
              
                added basic generate tests
              
              
                bigximik 124cfa7
              
                clean up
              
              
                bigximik fcef337
              
                updated interface and clean up
              
              
                bigximik 47ad6d0
              
                added from model case, renamed
              
              
                bigximik e066170
              
                added decorators to the  new test
              
              
                bigximik 24b3e1c
              
                added docs
              
              
                bigximik a574f94
              
                fixed typo
              
              
                bigximik 2094b60
              
                docs updates
              
              
                bigximik 196e73b
              
                cairosvg downgrade
              
              
                bigximik 7fe218d
              
                style filters applied
              
              
                bigximik f395bed
              
                Merge branch 'main' of github.com:ServiceNow/Fast-LLM into denis/geneβ¦
              
              
                bigximik 5325b50
              
                changed of handling of unwanted config deepcopy
              
              
                bigximik 2778925
              
                moved forward declaration to the right class
              
              
                bigximik 4829b0d
              
                changed asserts for clarity
              
              
                bigximik 1aa4344
              
                Added assert as fail safe
              
              
                bigximik 2b5fda6
              
                changes fixes and added test for return of hidden_states
              
              
                bigximik 77e7cbc
              
                added extra slow tests mark
              
              
                bigximik 4497436
              
                added faster tests with placeholder model
              
              
                bigximik File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or 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,77 @@ | ||
| --- | ||
| title: How to Generate with a Fast-LLM Model | ||
| --- | ||
|  | ||
| Fast-LLM models support `generate` and `forward` operations through Hugging Faceβcompatible wrappers. | ||
|  | ||
| β οΈ Limitations: | ||
|  | ||
| - No support for `cache`, `past_key_values`, `labels`, `attention` outputs, or `inputs_embeds` | ||
| - `position_ids` are ignored and reconstructed from the attention mask | ||
| - **model-parallel** and **sequence-data-parallel** generation is **not** supported | ||
|  | ||
| --- | ||
|  | ||
| ### π§ Generating Text from a Fast-LLM Model | ||
|  | ||
| Below is a step-by-step example of how to generate text using a Fast-LLM model checkpoint from Hugging Face Hub. | ||
|  | ||
| ```python | ||
| # Import dependencies | ||
| import huggingface_hub | ||
| from transformers import AutoTokenizer | ||
| from fast_llm.engine.checkpoint.config import CheckpointLoadConfig | ||
| from fast_llm.models.gpt.config import LlamaGPTHuggingfaceCheckpointFormat | ||
| from fast_llm.models.gpt.huggingface import HuggingfaceGPTModelForCausalLM | ||
|  | ||
| # Specify model and configuration | ||
| model = "HuggingFaceTB/SmolLM2-135M-Instruct" | ||
| checkpoint_format = LlamaGPTHuggingfaceCheckpointFormat | ||
| max_new_tokens = 50 | ||
|  | ||
| # Download model checkpoint from the Hugging Face Hub to a local directory | ||
| model_path = huggingface_hub.snapshot_download(repo_id=model, local_dir="/tmp") | ||
|  | ||
| # Load tokenizer from the downloaded model | ||
| tokenizer = AutoTokenizer.from_pretrained(model_path) | ||
|  | ||
| # Optional: updates to Fast-LLM config before loading the model | ||
| updates = { | ||
| ("base_model", "transformer", "use_flash_attention"): True, | ||
| ("distributed", "training_dtype"): "bf16" | ||
| } | ||
|  | ||
| # Load the model from the checkpoint with the given configuration | ||
| model = HuggingfaceGPTModelForCausalLM.from_pretrained( | ||
| CheckpointLoadConfig( | ||
| path=model_path, | ||
| format=checkpoint_format, | ||
| model_weights=True, | ||
| ), | ||
| updates, | ||
| ) | ||
|  | ||
| # Example input messages formatted for chat-style generation | ||
| messages = [ | ||
| {"role": "user", "content": "What is gravity?"}, | ||
| {"role": "user", "content": "Who is the president of EU?"}, | ||
| ] | ||
|  | ||
| # Convert messages into model input format using chat template | ||
| input_text = [tokenizer.apply_chat_template([el], tokenize=False) for el in messages] | ||
|  | ||
| # Prepare tokenized input for the model | ||
| tokenizer.padding_side = "left" # Important for correct padding | ||
| inputs = tokenizer(input_text, padding="longest", return_tensors="pt").to("cuda") | ||
|  | ||
| # Generate text using the model | ||
| outputs = model.generate(**inputs, max_new_tokens=max_new_tokens, use_cache=False) | ||
|  | ||
| # Decode and display outputs | ||
| outputs = [tokenizer.decode(el, skip_special_tokens=True) for el in outputs] | ||
|  | ||
| print("--------------------------------------------------------------------") | ||
| for el in outputs: | ||
| print(el) | ||
| print("--------------------------------------------------------------------") | ||
| ``` | ||
  
    
      This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't be published because of @249. I think the problem is missing variables in
Fast-LLM/.github/workflows/docs.yaml
Line 59 in 3ac976b
(Like those in
Fast-LLM/.github/workflows/docs.yaml
Line 34 in 3ac976b