Steps to Combine LLMs Using Knowledge Distillation

Step 1: Prepare the Environment

  1. Install Python and Libraries: Ensure you have Python installed. Install the necessary libraries:

    bash
    pip install torch transformers datasets
  2. Select the Models: Choose three top-performing open-source LLMs. For this example, let's use:

    • GPT-NeoX
    • BLOOM
    • LLaMA

Step 2: Load and Prepare the Models

  1. Load the Models: Create a Python script to load the models.
    python
    from transformers import AutoModelForCausalLM, AutoTokenizer # Load GPT-NeoX gpt_neox_model_name = "EleutherAI/gpt-neox-20B" gpt_neox_tokenizer = AutoTokenizer.from_pretrained(gpt_neox_model_name) gpt_neox_model = AutoModelForCausalLM.from_pretrained(gpt_neox_model_name) # Load BLOOM bloom_model_name = "bigscience/bloom" bloom_tokenizer = AutoTokenizer.from_pretrained(bloom_model_name) bloom_model = AutoModelForCausalLM.from_pretrained(bloom_model_name) # Load LLaMA llama_model_name = "meta-llama/LLaMA-13B" llama_tokenizer = AutoTokenizer.from_pretrained(llama_model_name) llama_model = AutoModelForCausalLM.from_pretrained(llama_model_name)

Step 3: Create a Student Model

  1. Define the Student Model: Use a smaller model architecture suitable for your hardware. You might start with a smaller GPT-2 model.

    python
    from transformers import GPT2LMHeadModel student_model_name = "gpt2" student_tokenizer = AutoTokenizer.from_pretrained(student_model_name) student_model = GPT2LMHeadModel.from_pretrained(student_model_name)
  2. Prepare a Dataset: Use a dataset for training the student model. You can use an open dataset like the WikiText dataset.

    python
    from datasets import load_dataset dataset = load_dataset("wikitext""wikitext-2-raw-v1")

Step 4: Distillation Training Loop

  1. Training Script: Create a training script for knowledge distillation.
    python
    import torch from torch.utils.data import DataLoader from transformers import AdamW # Function to generate logits from the teacher models def generate_teacher_logits(teacher_models, tokenizer, inputs): with torch.no_grad(): logits = [model(**inputs).logits for model in teacher_models] return torch.mean(torch.stack(logits), dim=0# Training loop def train_student_model(student_model, teacher_models, tokenizer, dataset, epochs=1, batch_size=2, lr=5e-5): student_model.train() optimizer = AdamW(student_model.parameters(), lr=lr) train_loader = DataLoader(dataset["train"], batch_size=batch_size) for epoch in range(epochs): for batch in train_loader: inputs = tokenizer(batch['text'], return_tensors='pt', padding=True, truncation=True) teacher_logits = generate_teacher_logits(teacher_models, tokenizer, inputs) student_outputs = student_model(**inputs) student_logits = student_outputs.logits loss = torch.nn.functional.mse_loss(student_logits, teacher_logits) optimizer.zero_grad() loss.backward() optimizer.step() print(f"Epoch: {epoch}, Loss: {loss.item()}") teacher_models = [gpt_neox_model, bloom_model, llama_model] train_student_model(student_model, teacher_models, student_tokenizer, dataset)

Step 5: Evaluate the Student Model

  1. Evaluation Script: Evaluate the performance of the distilled student model.
    python
    def evaluate_model(model, tokenizer, dataset, num_samples=100): model.eval() correct = 0 total = 0 eval_loader = DataLoader(dataset["test"], batch_size=1for i, batch in enumerate(eval_loader): if i >= num_samples: break inputs = tokenizer(batch['text'], return_tensors='pt', padding=True, truncation=Truewith torch.no_grad(): outputs = model(**inputs) predictions = torch.argmax(outputs.logits, dim=-1) labels = inputs['input_ids'] correct += (predictions == labels).sum().item() total += labels.numel() accuracy = correct / total print(f"Accuracy: {accuracy:.2f}") evaluate_model(student_model, student_tokenizer, dataset)

Step 6: Deploy the Student Model

  1. Update the Flask App: Modify the app.py to use the distilled student model.

    python
    from flask import Flask, request, jsonify, send_from_directory from transformers import GPT2LMHeadModel, AutoTokenizer import torch app = Flask(__name__) student_model_name = "gpt2" tokenizer = AutoTokenizer.from_pretrained(student_model_name) model = GPT2LMHeadModel.from_pretrained(student_model_name) model.to("cuda" if torch.cuda.is_available() else "cpu") model.eval() @app.route('/chat', methods=['POST']) def chat(): data = request.json user_input = data.get("message") inputs = tokenizer(user_input, return_tensors='pt', padding=True, truncation=True) inputs = {key: val.to("cuda" if torch.cuda.is_available() else "cpu"for key, val in inputs.items()} with torch.no_grad(): outputs = model(**inputs) response = tokenizer.decode(torch.argmax(outputs.logits, dim=-1)[0], skip_special_tokens=Truereturn jsonify({"response": response}) @app.route('/') def index(): return send_from_directory('''index.html'if __name__ == '__main__': app.run(host='0.0.0.0', port=5000)
  2. Deploy Follow the deployment steps for Heroku or VPS.

TESLA MODEL 3 - ALL VARIANTS COMPARED

A) REAL WORLD TESTING: 


B) ACCELERATION DATA COMPARISON

C) POWER, TORQUE & SPEED DATA COMPARISON



D) INDIVIDUAL MODEL DATA:

i) MODEL 3 PERFORMANCE GENERATION 1 (2019-24):


ii) MODEL 3 AWD + BOOST STATS:


iii) MODEL 3 AWD (NO BOOST) STATS:



iv) MODEL 3 Rear Wheel Drive (RWD) STATS:


References:
https://teslamotorsclub.com/tmc/threads/difference-in-acceleration-between-model-3-lr-w-boost-and-model-3p.266811/
https://www.reddit.com/r/teslamotors/comments/dqxnqt/model_3_performance_power_vs_speed_per_soc_fw/
https://www.reddit.com/r/teslamotors/comments/bcrbtg/model_3_awd_power_vs_speed_with_bonus_p3d/
https://imgur.com/a/model-3-awd-power-vs-speed-KrRYLYV
https://www.reddit.com/r/teslamotors/comments/gnrc0n/model_3_awd_waccel_boost_power_vs_speed_vs_state/
https://www.reddit.com/r/teslamotors/comments/bcrbtg/model_3_awd_power_vs_speed_with_bonus_p3d/
https://imgur.com/a/model-3-awd-power-vs-speed-fw-2019-8-5-7jahZEc
https://www.mountainpassperformance.com/tesla-model-3-lr-rwd-dyno-testing-various-soc/

DISCLAIMER: Remember all of the following are just general guidelines and should not be relied on as a precise source for information.
Full Screen Google Sheets

  

Key points to remember:

  • Pressure loss: As fluid flows through a pipe, it experiences pressure loss due to friction. Longer pipes and higher flow rates generally lead to greater pressure loss.
  • Noise: High flow velocities can cause noise in pipes. Minimizing noise often involves using larger pipes or reducing flow rates.
  • Safety: Exceeding the pressure rating of a pipe can be dangerous. Always consult with a qualified professional if you're unsure about the safe operating pressures for your piping system.


NOMOGRAPH: FLOW RATE vs PIPE SIZE


How to use a Nomograph:
  1. You should size your pipe so that your flow velocity stays in the green or yellow range.
  2. The green range is safest, most efficient and will produce little to no noise. 
  3. Flow velocities in the yellow range may be noisy and have additional back pressure. 
  4. Flow velocities in red are not recommended because of the risk of hydraulic shock and pipe/fitting/joint & pump failure.
  5. Find your flow in the first column (GPM) and then select the pipe size you want in the second column (pipe, ID in inches.) 
  6. Draw a straight line between them all the way to the last column. If the line ends up in the green you are good. If it ends in the yellow or red, increase the pipe size until your line ends in the green (best) or yellow (just okay) area.
NOTE: 
These figures are for straight pipe only! The effect of putting direction changes in will compound the back pressure even more and could even result in failure of the system or burning up the pump.
You will never be hurt by going to a bigger pipe and will gain by using less electricity due to a more efficient system which may offset the initial price difference for the larger pipe.



PVC material chemical resistance chart wrt Temperature



References:
https://cdn.flexpvc.com/graphics/head-loss-nomograph-chart.gif
https://flexpvc.com/docs/chemical-ratings.png
https://flexpvc.com/docs/ChemicalRatingsChartForPVCPlastics.pdf
https://flexpvc.com/Reference/FeetOfHeadPressureToPSIChart.pdf
https://flexpvc.com/Reference/PVC-Pipe-Weight-Per-Foot.shtml
https://flexpvc.com/Reference/WaterFlowBasedOnPipeSize.shtml
https://hy-techroofdrains.com/water-flow-through-a-pipe/

This article applies to the following nonimmigrant worker VISA classifications:
E-1, E-2, E-3, H-1B, H-1B1, L-1, O-1, TN and workers with pending I-485 for 180 days


When nonimmigrant workers are laid off & unable to find another job; they wrongly assume that they have to leave the US within 60 days. 
You can take one of the following actions within the grace period to be authorized to stay in the US for longer while you look for another job:

  1. Self-petition for a change of temporary change to nonimmigrant status (dependent, student, or visitor)
  2. Self-petition for a permanent change to immigrant status (EB1) concurrently with adjustment of status application (EB1 process is very long and complicated)
  3. File an application for an EAD (employment authorization document)
    if you already have an approved employment-based immigrant visa petition (I-140) and are facing compelling circumstances (VERY RARE)
  4. Leave the US temporarily to pause the 60days grace period, apply for US jobs while residing outside the US and return back to US whenever you get a new US job with a new visa stamp applicable to your new work authorization and new employer



Benefits:

  1. Allows time to request a change of status, continue job search, or applying for alternate work authorization
  2. Spouses with EAD or employment authorization incident to status may continue working during the grace period.
  3. Allows filing of a new work visa application to change status and further stop accrual of unlawful presence
  4. H-1B workers can begin work immediately after the new employer files a new H-1B petition.


Limitations:
  1. Applicants must maintain valid & legal US visa/status prior to filing status/visa change request
  2. Time from application start date to USCIS receipt date is counted against the grace 60days period irrespective of all facts/circumstances
  3. No employment authorization is DEPENDENT on appropriate change of status being approved
  4. Denial of change of status or extension of stay requests cannot be appealed but can be addressed through motions to reconsider or reopen, which unfortunately do not stop the accrual of unlawful presence.
  5. If the worker takes no action within the grace period, they and their dependents will need to depart the United States.



Reference:
https://www.uscis.gov/working-in-the-united-states/information-for-employers-and-employees/options-for-nonimmigrant-workers-following-termination-of-employment

Powered by Blogger.