publicclassListUtils{publicstatic<T>List<List<T>>partition(finalList<T> list,finalint size){if(list ==null){thrownewNullPointerException("List must not be null");}if(size <=0){thrownewIllegalArgumentException("Size must be greater than 0");}returnnewPartition<>(list, size);}privatestaticclassPartition<T>extendsAbstractList<List<T>>{privatefinalList<T> list;privatefinalint size;/*** * @param list 传入的列表* @param size 指定的长度,每size个数据切割为一个子列表*/privatePartition(finalList<T> list,finalint size){this.list = list;this.size = size;}/*** 获取按指定长度拆分后,索引位置的子列表* @param index* @return*/@OverridepublicList<T>get(finalint index){//获取拆分后子列表的个数finalint listSize =size();if(index <0){thrownewIndexOutOfBoundsException("Index "+ index +" must not be negative");}if(index >= listSize){thrownewIndexOutOfBoundsException("Index "+ index +" must be less than size "+listSize);}finalint start = index * size;finalint end =Math.min(start + size, list.size());//返回子列表return list.subList(start, end);}@Overridepublicintsize(){//(传入列表总长度/指定的长度)向上取整,即为拆分后子列表的个数return(int)Math.ceil((double) list.size()/(double) size);}@OverridepublicbooleanisEmpty(){return list.isEmpty();}}publicstaticvoidmain(String[] args){List<String> list=newArrayList<String>();for(int i =0; i <=2000; i++){list.add(i+"");}//将list每2000条数据拆分成一个子列表List<List<String>> partition =ListUtils.partition(list,2000);System.out.println("将list每2000条数据拆分成一个子列表:");System.out.println("子列表个数:"+partition.size());System.out.println("第二个子列表的内容:");partition.get(1).forEach(System.out::print);System.out.println("-------------------------------------------------------");System.out.println("将list每10条数据拆分成一个子列表:");List<List<String>> partition1 =ListUtils.partition(list,10);System.out.println("子列表个数:"+partition1.size());System.out.println("第三个子列表的内容:");partition1.get(2).forEach(s ->{System.out.print(s+" ");});}}
论文地址:https://arxiv.org/pdf/2307.09288.pdfd
代码地址:GitHub - facebookresearch/llama-recipes: Examples and recipes for Llama 2 model
问答
用了多少个gpu?
这篇文档中使用了3.3M GPU小时的计算,使用的硬件类型是A…