{"id":49325545,"url":"https://github.com/harryjackson/llm.java","last_synced_at":"2026-05-29T21:00:57.082Z","repository":{"id":238027021,"uuid":"787156584","full_name":"harryjackson/llm.java","owner":"harryjackson","description":"llm in java i.e. GPT2","archived":false,"fork":false,"pushed_at":"2024-05-05T07:35:32.000Z","size":75,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-05T08:30:04.917Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/harryjackson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-16T01:54:39.000Z","updated_at":"2024-05-05T07:35:35.000Z","dependencies_parsed_at":"2024-05-05T08:29:24.020Z","dependency_job_id":"e7389f50-7f7d-42c3-bd96-3afc9f3b2683","html_url":"https://github.com/harryjackson/llm.java","commit_stats":null,"previous_names":["harryjackson/llm.java"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/harryjackson/llm.java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harryjackson%2Fllm.java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harryjackson%2Fllm.java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harryjackson%2Fllm.java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harryjackson%2Fllm.java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harryjackson","download_url":"https://codeload.github.com/harryjackson/llm.java/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harryjackson%2Fllm.java/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33670211,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-29T02:00:06.066Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-26T20:00:31.589Z","updated_at":"2026-05-29T21:00:57.076Z","avatar_url":"https://github.com/harryjackson.png","language":"Java","funding_links":[],"categories":["人工智能"],"sub_categories":["推理引擎"],"readme":"# llm.java\n\nLarge Language Model (LLM) example in java i.e. GPT2. This is a port of \nthe [Llm.c code that lives here](https://github.com/karpathy/llm.c) written \nby @[karpathy](https://github.com/karpathy) \n\n## Before Running ChatGPT2 in Java\n\nBefore attempting to run this some prep work needs to happen. If you check \nthe [llm.c repository](https://github.com/karpathy/llm.c) these steps are very similar. \nThe reason the same code is in this repository is because LLM.c is still a moving target.\n\nI highly recommend running the original llm.c to see it work. It's wonderful.\n\n```bash\npython -m venv .venv\nsource .venv/bin/activate\npython -m pip install -r requirements.txt\npython prepro_tinyshakespeare.py\npython train_gpt2.py\n```\n\n### JVM Requirements\n\nI used the GraalVM for this running version 21. If you're using sdkman.\n\n```bash\nsdk default java 21.0.2-graalce\n```\n\nI tested the following JVM version and they all seem to work. I have not investigated why some are slower than \nothers.\n\n1. Temurin: This ran at half the speed of Graal. I stopped it at step 10\n\n```bash\nsdk install java 21-tem\nsdk use java 21-tem\n```\n\n2. Correto: This VM was also really slow compared to Graal. So I stopped it after step 10\n\n```bash\nsdk install java 21.0.3-amzn\nsdk use java 21.0.3-amzn\n```\n\n\n## Running\n\nNote the arguments passed to the JVM. Of particular note is \"-Djava.util.concurrent.ForkJoinPool.common.parallelism=10\", \nadjust this based on how many cores you have. The matrix multiplication methods are entirely CPU bound so adding more\nthreads than cores will just slow things down. \n\n```bash\nmvn clean install;\njava -jar -ea --add-modules jdk.incubator.vector --enable-preview -Xmx8g -Djava.util.concurrent.ForkJoinPool.common.parallelism=10 target/gpt2-1.0-SNAPSHOT.jar\n```\n\n## Performance\n\nI've made no attempt to tune this for performance. The C version is still much faster than this version. There are \nsome low-hanging fruit like parallelizing some of the loops. I made the matmul_forward and matmul_backward both \nparallel because it was painfully slow without it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharryjackson%2Fllm.java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharryjackson%2Fllm.java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharryjackson%2Fllm.java/lists"}