max / copy_v41_needed_files.py
manjunathan123's picture
Upload folder using huggingface_hub
071cd07 verified
Raw History Blame Contribute Delete
9.96 kB
#!/usr/bin/env python3
"""Safely copy SNN Baby Brain runtime companions and existing user data into v41's folder.
Default layout:
Old files: D:\\ais\\my_ai
v41 folder: D:\\ais\\my_ai\\new
Best use: place this script in D:\\ais\\my_ai\\new beside 41.py, then run:
python .\\copy_v41_needed_files.py
Safety rules:
- Never overwrites an existing destination file.
- Never copies old versioned .py scripts (20.py ... 40.py) over v41.
- Copies only a curated list of runtime state, model weights, and useful datasets.
- Use --dry-run first to preview, or --source/--destination to override paths.
"""
from __future__ import annotations
import argparse
import fnmatch
import json
import shutil
import sys
from datetime import datetime
from pathlib import Path
from typing import Iterable
DEFAULT_SOURCE = Path(r"D:\ais\my_ai")
DEFAULT_DESTINATION = Path(r"D:\ais\my_ai\new")
# Local runtime modules. The newer bundle's files are preserved whenever already present.
COMPANION_MODULES = {
"dev_workbench.py",
"human_workflow.py",
"ai_delegation.py",
"chronos_cognitive_module.py", # Optional; provides time-awareness helpers.
}
# Configuration files used by runtime features; only copied if destination lacks them.
CONFIG_FILES = {
"ai_workers.json",
"always_on_config.json",
"always_on_perception_config.json",
"always_on_desktop_config.json",
"system_prompt.txt",
}
# Main model state and training progress. Existing destination versions are never replaced.
CORE_STATE_FILES = {
"snn_brain_active.safetensors",
"brain_metadata.json",
"tokenizer_vocab.json",
"chat_data.json",
"replay_buffer.json",
"reasoning_log.jsonl",
"unsupervised_log.jsonl",
"skill_adapters.safetensors",
"skill_learning_state.json",
"skill_parameter_importance.safetensors",
"training_loss_log.csv",
"neurogenesis_events.jsonl",
"rl_feedback_log.csv",
"actor_critic.pt",
"jspace_workspace.safetensors",
"jspace_workspace_state.json",
"jspace_jacobian_lens.safetensors",
"jspace_jacobian_lens_state.json",
"training_autosave_progress.json",
"hippocampus_memory.jsonl",
"hippocampus_texts.json",
"hippocampus_vectors.npy",
"hippocampus_semantic_vectors.npy",
"memory.json",
"brain_memory.json",
"master_brain_state.json",
"bio_learning_v16.json",
"bio_memory_v16.json",
"capability_graph_v16.json",
"agi_retention.jsonl",
"agi_validation.jsonl",
"agi_manifest.json",
"identity.jsonl",
"identity_fast.jsonl",
"v15_cognitive_state.json",
"v15_goals.json",
"v15_skills.json",
"v15_world_model.json",
"metrics_v10.json",
"keywords.json",
"max.jsonl",
"maxa.json",
"max_dataset.json",
"max_chat_training.jsonl",
"my_knowledge_base.txt",
"my_knowledge_base1.txt",
"100 Moral Stories.txt",
# Optional legacy multimodal checkpoints used by v41 if compatible.
"vision_encoder.pt",
"vision_decoder.pt",
"audio_encoder.pt",
"audio_decoder.pt",
# Useful historical training/config files.
"curriculum.json",
"chat_json2.jsonl",
"chat_jsonl.jsonl",
"chat_jsonl2.jsonl",
"training_data.jsonl",
"image_data.jsonl",
"web_dataset.json",
"snn_name_training_1200.jsonl",
"snn_name_train_1200.jsonl",
"chatdoctor5k.json",
"xlam_function_calling_60k.json",
"prompts.csv",
"prompts.json",
"test.jsonl",
"tqa.json",
"teach1.json",
"data.json",
"data.json.jsonl",
"data.jsonl",
"data1.jsonl",
"data2.json",
"data2.jsonl",
"datah.json",
"datah.jsonl",
"m.json",
"my.json",
"max_dataset.json",
}
# Copy these matching curriculum files too, without bringing across old Python versions.
COPY_PATTERNS = (
"teach_generated_qa*.json",
"teach_curriculum_plan_*.json",
"l[1-6].json",
)
# Optional test / reference files are not needed for runtime, but useful if available.
OPTIONAL_SUPPORT_FILES = {
"check_v41_regressions.py",
"test_lifelong_growth_v41.py",
"SNN_Baby_Brain_41_IMPLEMENTATION_MATRIX.md",
"README_SNN_Baby_Brain_41.md",
"requirements-40-core.txt",
"requirements-40-optional.txt",
}
def choose_paths(args: argparse.Namespace) -> tuple[Path, Path]:
if args.source:
source = Path(args.source).expanduser().resolve()
else:
# If the helper is placed beside 41.py in a folder named "new", use its parent as source.
here = Path(__file__).resolve().parent
if here.name.lower() == "new" and (here / "41.py").exists():
source = here.parent
else:
source = DEFAULT_SOURCE
if args.destination:
destination = Path(args.destination).expanduser().resolve()
else:
here = Path(__file__).resolve().parent
if (here / "41.py").exists():
destination = here
else:
destination = DEFAULT_DESTINATION
return source, destination
def selected_names(source: Path, include_optional_support: bool) -> list[str]:
names = set(COMPANION_MODULES | CONFIG_FILES | CORE_STATE_FILES)
if include_optional_support:
names.update(OPTIONAL_SUPPORT_FILES)
# Add patterns only for existing top-level files in the old folder.
for candidate in source.iterdir():
if candidate.is_file() and any(fnmatch.fnmatch(candidate.name.lower(), p.lower()) for p in COPY_PATTERNS):
names.add(candidate.name)
return sorted(names, key=str.lower)
def main() -> int:
parser = argparse.ArgumentParser(description="Copy old SNN Baby Brain state/data into the folder containing v41.py, without overwriting anything.")
parser.add_argument("--source", help=r"Old files folder (default: D:\ais\my_ai or parent of the folder named new).")
parser.add_argument("--destination", help=r"v41 folder (default: folder containing this script/41.py, or D:\ais\my_ai\new).")
parser.add_argument("--dry-run", action="store_true", help="Show what would be copied without changing any files.")
parser.add_argument("--include-support", action="store_true", help="Also copy the regression tests, README, and requirements files if present.")
args = parser.parse_args()
source, destination = choose_paths(args)
print("SNN Baby Brain v41 file copier")
print(f"Source : {source}")
print(f"Destination : {destination}")
print(f"Mode : {'DRY RUN (no files changed)' if args.dry_run else 'COPY MISSING FILES ONLY'}")
if not source.is_dir():
print(f"ERROR: Old files folder does not exist: {source}", file=sys.stderr)
return 2
if not destination.is_dir():
print(f"ERROR: v41 destination folder does not exist: {destination}", file=sys.stderr)
print("Extract the v41 bundle there first, then run this script from that folder.", file=sys.stderr)
return 2
if not (destination / "41.py").is_file():
print(f"ERROR: {destination / '41.py'} was not found. Refusing to copy into an uncertain folder.", file=sys.stderr)
return 2
if source.resolve() == destination.resolve():
print("ERROR: Source and destination are the same folder; nothing to do.", file=sys.stderr)
return 2
names = selected_names(source, args.include_support)
copied: list[str] = []
skipped_existing: list[str] = []
missing_source: list[str] = []
failed: list[dict[str, str]] = []
for name in names:
src = source / name
dst = destination / name
if not src.is_file():
missing_source.append(name)
continue
if dst.exists():
skipped_existing.append(name)
continue
if args.dry_run:
print(f"[WOULD COPY] {name} ({src.stat().st_size:,} bytes)")
copied.append(name)
continue
try:
shutil.copy2(src, dst)
copied.append(name)
print(f"[COPIED] {name} ({src.stat().st_size:,} bytes)")
except Exception as exc:
failed.append({"file": name, "error": str(exc)})
print(f"[FAILED] {name}: {exc}", file=sys.stderr)
if skipped_existing:
print(f"\nPreserved {len(skipped_existing)} destination file(s) already present (not overwritten).")
if missing_source:
print(f"Source did not contain {len(missing_source)} optional/legacy file(s); skipped them.")
print(f"\nSummary: {'would copy' if args.dry_run else 'copied'}={len(copied)}, already present={len(skipped_existing)}, unavailable in source={len(missing_source)}, failed={len(failed)}")
# Give the user a quick check of critical runtime files after the copy.
print("\nDestination check:")
for name in ("41.py", "dev_workbench.py", "human_workflow.py", "ai_delegation.py", "snn_brain_active.safetensors", "brain_metadata.json", "tokenizer_vocab.json"):
status = "OK" if (destination / name).is_file() else "MISSING"
print(f" [{status}] {name}")
if not args.dry_run:
report = {
"created_at": datetime.now().astimezone().isoformat(timespec="seconds"),
"source": str(source),
"destination": str(destination),
"copied": copied,
"skipped_existing": skipped_existing,
"missing_source": missing_source,
"failed": failed,
}
report_path = destination / "v41_file_copy_report.json"
try:
report_path.write_text(json.dumps(report, indent=2, ensure_ascii=False), encoding="utf-8")
print(f"\nReport saved to: {report_path}")
except Exception as exc:
print(f"WARNING: Could not save copy report: {exc}", file=sys.stderr)
print("\nSafety: no files in the destination were overwritten. Old versioned .py files were not copied.")
return 1 if failed else 0
if __name__ == "__main__":
raise SystemExit(main())