Παραμετροποίηση και εκπαίδευση των Large Language Models ανοικτού κώδικα
Φόρτωση...
Ημερομηνία
2025-07-21
Συγγραφείς
Τίτλος Εφημερίδας
Περιοδικό ISSN
Τίτλος τόμου
Εκδότης
ΕΛΜΕΠΑ, Σχολή Μηχανικών (ΣΜΗΧ), Τμήμα Ηλεκτρολόγων Μηχανικών και Μηχανικών Υπολογιστών
Επιβλέπων
Περίληψη
Σκοπός της πτυχιακής αυτής ήταν η μελέτη των τεχνολογιών που εσωκλείονται στα
Μεγάλα Γλωσσικά Μοντέλα, και η χρησιμοποίηση των απαραίτητων τεχνικών για τον
σχεδιασμό και την υλοποίηση μίας μετεκπαίδευσης, την εξειδίκευση δηλαδή ενός μοντέλου
σε έναν συγκεκριμένο τομέα τον οποίο δε γνώριζε μετά το τέλος της βασικής του
εκπαίδευσης. Για το λόγο αυτό, μελετήθηκαν όλα τα απαραίτητα βήματα αυτής της
διαδικασίας, από την τμηματοποίηση του κειμένου (tokenization) μέσω των κατάλληλων
αλγόριθμων όπως ο Byte-Pair Encoding (BPE) και frameworks όπως το SentencePiece, μέχρι
την επεξεργασία την οποία εφαρμόζει η αρχιτεκτονική Transformer για να μετασχηματίσει
την είσοδο σε κάτι ουσιώδες το οποίο μπορεί το μοντέλο να κατανοήσει. Μέσα από τη
συγκεκριμένη μελέτη έγινε σαφής η ικανότητα των μοντέλων αυτών να χρησιμοποιούν τη
γενική, προϋπάρχουσα γνώση τους έτσι ώστε να προσαρμόζονται γρήγορα και αποδοτικά σε
νέα σύνολα δεδομένων, πολύ μικρότερα από αυτά στα οποία αρχικά εκπαιδεύτηκαν.
Πιο συγκεκριμένα, χρησιμοποιήθηκε η ανοικτού κώδικα βιβλιοθήκη Transformers του
Hugging Face, η οποία μας επιτρέπει να φορτώνουμε και να διαχειριζόμαστε εύκολα
οποιοδήποτε Μεγάλο Γλωσσικό Μοντέλο θέλουμε. Αυτό που επιλέχθηκε ήταν το Llama2-
chat μοντέλο των 7 δισεκατομμυρίων παραμέτρων της Meta AI. Λόγω των απαιτήσεων
μνήμης και πόρων που το συνοδεύουν, χρησιμοποιήθηκαν τεχνικές κβαντοποίησης όπως η
QLoRA της BitsAndBytes βιβλιοθήκης για να φορτωθεί το μοντέλο σε μικρότερη ακρίβεια
από την αρχική, και τεχνικές μετεκπαίδευσης όπως η LoRA για να μειωθούν οι απαιτήσεις
VRAM έως και 4 φορές. Για την υλοποίησή της, χρησιμοποιήθηκε η cloud πλατφόρμα
Google Colab, μέσω της οποίας έγινε εφικτό να τρέξει ο κώδικας της μετεκπαίδευσης σε
τελευταίας τεχνολογίας hardware όπως η A100 GPU, η οποία την επιτάχυνε δραματικά και
επέτρεψε τον πειραματισμό με πολλές διαφορετικές ρυθμίσεις παραμέτρων για να βρεθεί μία
ουσιώδης και αποτελεσματική υλοποίηση, στην οποία καταλήξαμε αξιολογώντας τις
μετρήσεις όλων των μετεκπαιδεύσεων μέσω της Weights & Biases πλατφόρμας. Η
εξειδίκευση που επιχειρήθηκε ήταν πάνω σε μία εσωτερική προγραμματιστική γλώσσα, την
LOLCODE, της οποίας το συντακτικό και η απλή, αλλά αντισυμβατική λογική, παρουσιάζει
συγκεκριμένες προκλήσεις τις οποίες πρέπει να αντιμετωπίσει το μοντέλο για να μπορεί να
παράξει σωστό κώδικα. Για παράδειγμα, λέξεις-κλειδιά της γλώσσας αυτής όπως το
“KTHXBYE” δεν υπάρχουν στο λεξιλόγιο του μοντέλου, και η τμηματοποίησή τους οφείλει
να γίνει με τρόπο που θα επιφέρει ουσιαστικά και αξιόλογα αποτελέσματα, βοηθώντας το
μοντέλο να συλλάβει το νόημα και τον σκοπό για τον οποίο χρησιμοποιούνται.
Έτσι, το μοντέλο που αναπτύχθηκε έδειξε μία αξιόλογη προσαρμογή στο σύνολο
δεδομένων, καθώς παρατηρήθηκε σωστό συντακτικό και χρήση των εντολών της γλώσσας
αυτής. Συγκριτικά με το βασικό μοντέλο, το οποίο δεν είχε καμία ουσιαστική γνώση και ο
κώδικας που παρήγαγε ήταν γραμμένος στην Python, και λαμβάνοντας υπόψιν ότι το σύνολο
δεδομένων μας ήταν σχετικά μικρό, μπορούμε να πούμε ότι η μετεκπαίδευση ήταν επιτυχής
και τα αποτελέσματά της ενθαρρυντικά.
The goal of this thesis was to study the technologies behind Large Language Models (LLMs), and to use all the necessary techniques in order to design and implement a finetuning, meaning a specialization of a LLM to a field that it hasn't been pre-trained on. For this reason, an analysis of all the necessary steps was made, from the crucial first step of tokenization, which seperates the corpus in words, characters and sub-words, based on specific algorithms like Byte-Pair Encoding (BPE) and frameworks like SentencePiece, to the Transformers architecture and the processing it implements in order to extract meaning and corellations between words. Throughout this study, it was made obvious that the ability of these models to use their existent, vast general knowledge in order to specialize effectively on new datasets is unparalleled and produces state-of-the-art results. Specifically, the Transformers library from the Hugging Face ecosystem was used, which provides all the necessary procedures in order to load and process any LLM from the Hub. The one that was chosen was Llama2-7b-chat model from Meta AI. Due to the high demands of computational power, quantization techniques like QLoRA that is included in the BitsandBytes library were implemented, in order to load the model in a lower precision, and fine-tuning techniques like LoRA which decreases the VRAM needed by up to 4 times. The implementation was made on the Google Colaboratory cloud platform, which enabled us to run the fine-tuning code on state-of-the-art GPU's like A100 that accellerated the process drastically, allowing the experimentation of different parameter settings in order to find a meaningful and effective fine-tuned model. The evaluation was carried out through the Weights & Biases platform, which was used to visualize and compare all the critical measurements among the implementations. The specialization was aimed at an esoteric programming language, LOLCODE, which has a unique syntax that poses significant challenges for the model to face in order to produce correct and accurate code. For instance, this language uses keywords like “KTHXBYE” that do not exist in the base vocabulary of the model, and their tokenization needs to be done in a way that it will help the model to grasp the context and the reason each one of these keywords is used. Thus, the model produced showed a significant adjustment to the dataset it was provided with, since correct syntax and usage of the appropriate keywords was observed. Compared to the basic model, which has no knowledge of this language and the code it produced was in Python, and also taking into account that the dataset was relatively small, we can say that the fine-tuning was successful and the results were meaningful and encouraging.
The goal of this thesis was to study the technologies behind Large Language Models (LLMs), and to use all the necessary techniques in order to design and implement a finetuning, meaning a specialization of a LLM to a field that it hasn't been pre-trained on. For this reason, an analysis of all the necessary steps was made, from the crucial first step of tokenization, which seperates the corpus in words, characters and sub-words, based on specific algorithms like Byte-Pair Encoding (BPE) and frameworks like SentencePiece, to the Transformers architecture and the processing it implements in order to extract meaning and corellations between words. Throughout this study, it was made obvious that the ability of these models to use their existent, vast general knowledge in order to specialize effectively on new datasets is unparalleled and produces state-of-the-art results. Specifically, the Transformers library from the Hugging Face ecosystem was used, which provides all the necessary procedures in order to load and process any LLM from the Hub. The one that was chosen was Llama2-7b-chat model from Meta AI. Due to the high demands of computational power, quantization techniques like QLoRA that is included in the BitsandBytes library were implemented, in order to load the model in a lower precision, and fine-tuning techniques like LoRA which decreases the VRAM needed by up to 4 times. The implementation was made on the Google Colaboratory cloud platform, which enabled us to run the fine-tuning code on state-of-the-art GPU's like A100 that accellerated the process drastically, allowing the experimentation of different parameter settings in order to find a meaningful and effective fine-tuned model. The evaluation was carried out through the Weights & Biases platform, which was used to visualize and compare all the critical measurements among the implementations. The specialization was aimed at an esoteric programming language, LOLCODE, which has a unique syntax that poses significant challenges for the model to face in order to produce correct and accurate code. For instance, this language uses keywords like “KTHXBYE” that do not exist in the base vocabulary of the model, and their tokenization needs to be done in a way that it will help the model to grasp the context and the reason each one of these keywords is used. Thus, the model produced showed a significant adjustment to the dataset it was provided with, since correct syntax and usage of the appropriate keywords was observed. Compared to the basic model, which has no knowledge of this language and the code it produced was in Python, and also taking into account that the dataset was relatively small, we can say that the fine-tuning was successful and the results were meaningful and encouraging.
Περιγραφή
Λέξεις-κλειδιά
Επεξεργασία φυσικής γλώσσας, Μεγάλα γλωσσικά μοντέλα, Natural language processing, Large Language Models (LLMs)