Safetensors
English
Files changed (1) hide show
  1. README.md +141 -0
README.md CHANGED
@@ -1,4 +1,145 @@
 
 
 
 
 
 
 
 
1
 
2
  # Bioinspired3D
3
 
4
  Fine-tuned version of meta-llama/Llama-3.2-3B-Instruct using LoRA adapters for Blender code generation for bioinspired 3D models.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ datasets:
3
+ - lamm-mit/Bioinspired3D
4
+ language:
5
+ - en
6
+ base_model:
7
+ - meta-llama/Llama-3.2-3B-Instruct
8
+ ---
9
 
10
  # Bioinspired3D
11
 
12
  Fine-tuned version of meta-llama/Llama-3.2-3B-Instruct using LoRA adapters for Blender code generation for bioinspired 3D models.
13
+
14
+ ## Abstract
15
+
16
+ Generative AI has made rapid progress in text, image, and video synthesis, yet text-to-3D modeling for
17
+ scientific design remains particularly challenging due to limited controllability and high computational
18
+ cost. Most existing 3D generative methods rely on meshes, voxels, or point clouds which can be costly
19
+ to train and difficult to control. We introduce Bioinspired123D, a lightweight and modular code-
20
+ as-geometry pipeline that generates fabricable 3D structures directly through parametric programs
21
+ rather than dense visual representations. At the core of Bioinspired123D is Bioinspired3D, a compact
22
+ language model finetuned to translate natural language design cues into Blender Python scripts
23
+ encoding smooth, biologically inspired geometries. We curate a domain-specific dataset of over
24
+ 4,000 bioinspired and geometric design scripts spanning helical, cellular, and tubular motifs with
25
+ parametric variability. The dataset is expanded and validated through an automated LLM-driven,
26
+ Blender-based quality control pipeline. Bioinspired3D is then embedded in a graph-based agentic
27
+ framework that integrates multimodal retrieval-augmented generation and a vision–language model
28
+ critic to iteratively evaluate, critique, and repair generated scripts. We evaluate performance on a new
29
+ benchmark for 3D geometry script generation and show that Bioinspired123D demonstrates a near
30
+ fourfold improvement over its unfinetuned base model, while also outperforming substantially larger
31
+ state-of-the-art language models despite using far fewer parameters and compute. By prioritizing
32
+ code-as-geometry representations, Bioinspired123D enables compute-efficient, controllable, and
33
+ interpretable text-to-3D generation, lowering barriers to AI driven scientific discovery in materials
34
+ and structural design.
35
+
36
+ ## What’s in this repo (Hugging Face)
37
+
38
+ This Hugging Face release contains **Bioinspired3D only**: a LoRA adapter that you load on top of the base model to generate **Blender Python scripts from natural-language prompts**.
39
+
40
+ For the full **Bioinspired123D** agentic framework (retrieval + VLM critic + iterative repair), see the GitHub repo:
41
+ https://github.com/lamm-mit/Bioinspired123D
42
+
43
+ ## Usage
44
+
45
+ ### Install
46
+
47
+ ```bash
48
+ pip install -U transformers accelerate peft torch
49
+ ```
50
+
51
+ ### Load the base model + LoRA adapter
52
+ ```bash
53
+ from transformers import AutoTokenizer, AutoModelForCausalLM
54
+ from peft import PeftModel
55
+ import torch
56
+
57
+ BASE_MODEL = "meta-llama/Llama-3.2-3B-Instruct"
58
+ LORA_ADAPTER = "rachelkluu/bioinspired3D"
59
+
60
+ # Set this to your preferred device, e.g. "cuda:0" or "cpu"
61
+ DEVICE_3D = "cuda:0"
62
+
63
+ bio3d_tok = AutoTokenizer.from_pretrained(BASE_MODEL)
64
+
65
+ base_model = AutoModelForCausalLM.from_pretrained(
66
+ BASE_MODEL,
67
+ torch_dtype=torch.float16,
68
+ device_map={"": DEVICE_3D},
69
+ )
70
+
71
+ bio3d_model = PeftModel.from_pretrained(base_model, LORA_ADAPTER)
72
+ bio3d_model.eval()
73
+
74
+ def format_input(prompt: str) -> str:
75
+ return (
76
+ "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n"
77
+ "You are a helpful assistant<|eot_id|>"
78
+ "<|start_header_id|>user<|end_header_id|>\n\n"
79
+ f"{prompt}<|eot_id|>"
80
+ "<|start_header_id|>assistant<|end_header_id|>\n\n"
81
+ )
82
+ ```
83
+ ### Load utility functions
84
+ ```bash
85
+ def extract_blender_code(model_out: str) -> str:
86
+ matches = list(re.finditer(r"```python\s*(.*?)```", model_out, flags=re.DOTALL))
87
+ if matches:
88
+ return matches[-1].group(1).strip()
89
+ pos = model_out.rfind("import bpy")
90
+ return model_out[pos:].strip() if pos != -1 else model_out.strip()
91
+
92
+
93
+ def clean_blender_code(text: str) -> str:
94
+ if not text:
95
+ return "import bpy"
96
+ code = text.strip()
97
+ code = code.replace("```python", "").replace("```", "")
98
+ code = re.sub(r"[\x00-\x08\x0b-\x1f]", "", code)
99
+ if not code.lstrip().startswith("import bpy"):
100
+ code = "import bpy\n" + code
101
+ return code
102
+ ```
103
+ ### Generate Blender code from a natural-language prompt
104
+ ```bash
105
+ prompt = """Write Blender code to make a cellular structure."""
106
+
107
+ formatted = format_input(prompt)
108
+ inputs = bio3d_tok(formatted, return_tensors="pt").to(bio3d_model.device)
109
+
110
+ with torch.no_grad():
111
+ outputs = bio3d_model.generate(
112
+ **inputs,
113
+ max_new_tokens=2048,
114
+ do_sample=True,
115
+ temperature=0.1,
116
+ top_p=0.9,
117
+ )
118
+
119
+ raw = bio3d_tok.decode(outputs[0], skip_special_tokens=True)
120
+ raw_code = extract_blender_code(raw)
121
+ blender_code = clean_blender_code(raw_code)
122
+
123
+ print(blender_code)
124
+ ```
125
+ ### Prompting tips
126
+
127
+ Input: Natural language design intent (for example: “tubular structure with noisy placement”, “helical material with cylindrical fibers”, “smoothed cellular structure”).
128
+
129
+ Output: A Blender Python script (intended to be executed in Blender) that constructs the requested geometry.
130
+
131
+ To encourage explicit reasoning, append a variant of: “Think step by step.” to the end of your prompt. For example: "Write Blender code to make a tubular structure with z-aligned tubules. Think step by step."
132
+
133
+ ### Notes:
134
+ This adapter is meant to be used with the specified base model. Generated scripts should be treated like code: run in a sandboxed environment and validate geometry as needed.
135
+
136
+ ## Citation
137
+
138
+ If you use Bioinspired3D or the broader Bioinspired123D framework in your work, please cite:
139
+
140
+ ```bibtex
141
+ @article{luu2026bioinspired123d,
142
+ title={Bioinspired123D: Generative 3D Modeling System for Bioinspired Structures},
143
+ author={Luu, Rachel K. and Buehler, Markus J.},
144
+ year={2026}
145
+ }