Download scripts/generate_report.py from mohit-vashishta/bhaari-ai-code: direct link, hf CLI and curl.
- Browser
- Download file 6.61 kB
-
https://huggingface.co/mohit-vashishta/bhaari-ai-code/resolve/main/scripts/generate_report.py
- Command line
-
hf download hf://mohit-vashishta/bhaari-ai-code/scripts/generate_report.py
-
curl -L -o generate_report.py https://huggingface.co/mohit-vashishta/bhaari-ai-code/resolve/main/scripts/generate_report.py
6.61 kB
| """ | |
| Generate PDF Report for Bhaari AI Training Steps | |
| """ | |
| import os | |
| from datetime import datetime | |
| from pathlib import Path | |
| from fpdf import FPDF | |
| class BhaariReport(FPDF): | |
| def header(self): | |
| self.set_font('Helvetica', 'B', 16) | |
| self.cell(0, 10, 'Bhaari AI - Training Report', 0, 1, 'C') | |
| self.ln(5) | |
| def footer(self): | |
| self.set_y(-15) | |
| self.set_font('Helvetica', 'I', 8) | |
| self.cell(0, 10, f'Page {self.page_no()}/{{nb}}', 0, 0, 'C') | |
| def section_title(self, title): | |
| self.set_font('Helvetica', 'B', 14) | |
| self.set_text_color(0, 51, 102) | |
| self.cell(0, 10, title, 0, 1, 'L') | |
| self.set_draw_color(0, 51, 102) | |
| self.line(10, self.get_y(), 200, self.get_y()) | |
| self.ln(5) | |
| self.set_text_color(0, 0, 0) | |
| def body_text(self, text): | |
| self.set_font('Helvetica', '', 11) | |
| self.multi_cell(0, 6, text) | |
| self.ln(3) | |
| def add_table(self, headers, data, col_widths=None): | |
| if col_widths is None: | |
| col_widths = [190 // len(headers)] * len(headers) | |
| # Header | |
| self.set_font('Helvetica', 'B', 10) | |
| self.set_fill_color(0, 51, 102) | |
| self.set_text_color(255, 255, 255) | |
| for i, header in enumerate(headers): | |
| self.cell(col_widths[i], 8, header, 1, 0, 'C', True) | |
| self.ln() | |
| # Data | |
| self.set_text_color(0, 0, 0) | |
| self.set_font('Helvetica', '', 10) | |
| fill = False | |
| for row in data: | |
| for i, cell in enumerate(row): | |
| self.cell(col_widths[i], 7, str(cell), 1, 0, 'C', fill) | |
| self.ln() | |
| fill = not fill | |
| def generate_tokenizer_report(tokenizer_stats, training_data_stats, test_results, output_path=None): | |
| """Generate PDF report for tokenizer training""" | |
| if output_path is None: | |
| timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") | |
| output_path = f"reports/bhaari_tok_report_{timestamp}.pdf" | |
| os.makedirs(os.path.dirname(output_path), exist_ok=True) | |
| pdf = BhaariReport() | |
| pdf.alias_nb_pages() | |
| pdf.add_page() | |
| # Title | |
| pdf.set_font('Helvetica', 'B', 20) | |
| pdf.set_text_color(0, 51, 102) | |
| pdf.cell(0, 15, 'BhaariTok Tokenizer Training Report', 0, 1, 'C') | |
| pdf.ln(5) | |
| # Metadata | |
| pdf.set_font('Helvetica', '', 11) | |
| pdf.set_text_color(0, 0, 0) | |
| pdf.cell(0, 7, f'Date: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}', 0, 1) | |
| pdf.cell(0, 7, f'GPU: L40S (Lightning AI Studio)', 0, 1) | |
| pdf.cell(0, 7, f'Vocab Size: {tokenizer_stats.get("vocab_size", "N/A")}', 0, 1) | |
| pdf.ln(10) | |
| # Section 1: Training Summary | |
| pdf.section_title('1. Training Summary') | |
| pdf.body_text( | |
| f"BhaariTok tokenizer trained with Llama 3 regex pattern and byte-level BPE. " | |
| f"Target vocabulary size: 128,000 tokens with multi-language support." | |
| ) | |
| # Training stats table | |
| pdf.section_title('1.1 Tokenizer Statistics') | |
| headers = ['Parameter', 'Value'] | |
| data = [ | |
| ['Vocab Size', str(tokenizer_stats.get('vocab_size', 'N/A'))], | |
| ['Total Merges', str(tokenizer_stats.get('total_merges', 'N/A'))], | |
| ['Special Tokens', str(tokenizer_stats.get('special_tokens', 'N/A'))], | |
| ['Byte Vocab', '256 (byte-level)'], | |
| ['Regex Pattern', 'Llama 3'], | |
| ] | |
| pdf.add_table(headers, data, [95, 95]) | |
| pdf.ln(5) | |
| # Section 2: Training Data | |
| pdf.section_title('2. Training Data') | |
| pdf.body_text("Multi-language code corpus used for training:") | |
| headers = ['Dataset', 'Language', 'Samples'] | |
| data = training_data_stats.get('datasets', []) | |
| pdf.add_table(headers, data, [70, 60, 60]) | |
| pdf.ln(5) | |
| pdf.body_text(f"Total training samples: {training_data_stats.get('total_samples', 'N/A')}") | |
| # Section 3: Test Results | |
| pdf.section_title('3. Test Results') | |
| headers = ['Test Case', 'Tokens', 'Decoded Match'] | |
| data = [] | |
| for test in test_results: | |
| data.append([ | |
| test['input'][:40] + '...', | |
| str(test['num_tokens']), | |
| 'Yes' if test['match'] else 'No' | |
| ]) | |
| pdf.add_table(headers, data, [80, 30, 40]) | |
| pdf.ln(5) | |
| # Section 4: Special Tokens | |
| pdf.section_title('4. Special Tokens') | |
| pdf.body_text("Reserved tokens for reasoning, code execution, self-correction, and future multimodal:") | |
| special_tokens = tokenizer_stats.get('special_token_list', {}) | |
| headers = ['Token', 'ID', 'Purpose'] | |
| data = [] | |
| for token, token_id in list(special_tokens.items())[:15]: | |
| purpose = 'Control' if token_id < 128003 else 'Language' if token_id < 128011 else 'Reasoning' if token_id < 128013 else 'Code' if token_id < 128021 else 'Correction' if token_id < 128024 else 'Repo' if token_id < 128100 else 'Multimodal' | |
| data.append([token, str(token_id), purpose]) | |
| pdf.add_table(headers, data, [60, 25, 105]) | |
| pdf.ln(5) | |
| # Section 5: Next Steps | |
| pdf.section_title('5. Next Steps') | |
| pdf.body_text( | |
| "1. Train BhaariCore-1M model on CPU\n" | |
| "2. Scale to BhaariCore-10M on L40S GPU\n" | |
| "3. Add MoE (8 experts, top-2 routing)\n" | |
| "4. Implement Multi-Token Prediction (4 tokens)\n" | |
| "5. Add self-correction loop\n" | |
| "6. Add code execution feedback\n" | |
| "7. Multi-language training (Python + JS + Rust)\n" | |
| "8. Repository context (32K tokens)\n" | |
| "9. Test-driven training\n" | |
| "10. Incremental learning (EWC + replay)\n" | |
| "11. Internet crawler + continuous learning" | |
| ) | |
| # Save | |
| pdf.output(output_path) | |
| print(f"Report saved to: {output_path}") | |
| return output_path | |
| if __name__ == "__main__": | |
| # Test report generation | |
| test_stats = { | |
| 'vocab_size': 128000, | |
| 'total_merges': 127744, | |
| 'special_tokens': 256, | |
| 'special_token_list': { | |
| '<|begin_of_text|>': 128000, | |
| '<|end_of_text|>': 128001, | |
| '<|python|>': 128003, | |
| '<|javascript|>': 128004, | |
| '<|reasoning_start|>': 128011, | |
| } | |
| } | |
| test_data = { | |
| 'datasets': [ | |
| ['bigcode/the-stack-v2', 'Python, JS, Rust', '500,000'], | |
| ['HuggingFaceTB/stack-edu', 'Python', '100,000'], | |
| ], | |
| 'total_samples': '600,000' | |
| } | |
| test_results = [ | |
| {'input': 'def hello(): pass', 'num_tokens': 8, 'match': True}, | |
| {'input': 'const x = 5;', 'num_tokens': 6, 'match': True}, | |
| ] | |
| generate_tokenizer_report(test_stats, test_data, test_results) | |